Ask a Question related to Coldfusion Database Access, Design and Development.
-
Buda123 #1
Sub Query problem
I have one simple question,
this is my query:
SELECT users.*, (SELECT TOP 1 Product_name FROM Products WHERE user_id =
users.user_id) AS Product
FROM users
Query is working fine, it returns all users and products which are tied to
users, problem is when I am filtering data by product (subquery) I don't want
all users only users which are tied to product.
Did anyone had this before, thanks
Buda123 Guest
-
Query problem, please help.
mysql Ver 12.22 Distrib 4.0.24, for pc-linux-gnu (i386) gives me: The following database Error occured: You have an error in your SQL syntax.... -
***Sql Query problem
Randy Webb wrote: SELECT DISTINCT OrderID FROM trans WHERE Trans_ID = 1 AND OrderID NOT IN (SELECT DISTINCT OrderID FROM trans WHERE Trans_ID =... -
Query of Query problem
Error Executing Database Query. Query Of Queries runtime error. Table named "DATA" was not found in Memory. It is misspelled, or the table is... -
Query on Query and CF casting problem
I am using a custom tag in MX7 that was working fine in 5 that renders a table. The input to the custom tag is a query and it's columns along with... -
query problem
SELECT top5.PRODID, p.PRODNAME FROM ( SELECT TOP 5 SALES = COUNT(*), PRODID FROM SALES GROUP BY PRODID ORDER BY SALES DESC ) AS top5 INNER JOIN... -
paross1 #2
Re: Sub Query problem
Hmmm, if I am reading this right, I would say that you would want to add a a
parameter to the where clause of your sub-select restricting your query to a
specific product, something like this:
SELECT users.*,
(SELECT TOP 1 Product_name
FROM Products
WHERE user_id = users.user_id
AND Product_name = '#productname#') AS Product
FROM users
You could make it optional with <cfif> tags so that if your #productname# is
blank, or doesn't exist, you return users for all products.
Phil
paross1 Guest
-
Buda123 #3
Re: Sub Query problem
Thanks Phil,
I wanted to avoid <if> statements in loop since I have 6-7 filters, I wanted
to solve everithing inside query. I got the solution, last night was long :),
Here it is if anybody need it in the future:
SELECT users.*, (SELECT TOP 1 Product_name FROM Products WHERE user_id =
users.user_id <cfif isDefined('Form.bill_end_date')>AND bill_end_date <
#CreateODBCDate(Form.bill_end_date)#</cfif>) AS Product
FROM users
<cfif isDefined('Form.bill_end_date')>
WHERE user_id IN (SELECT user_id FROM Products <cfif
isDefined('Form.bill_end_date')>WHERE bill_end_date <
#CreateODBCDate(Form.bill_end_date)#</cfif>)
</cfif>
Buda123 Guest
-
paross1 #4
Re: Sub Query problem
I meant by using <cfif> tags within your query, which is exactly what you ended up doing. :D
Phil
paross1 Guest



Reply With Quote

