Link to home
Start Free TrialLog in
Avatar of doramail05
doramail05Flag for Malaysia

asked on

Getting SQL Select parameter and apply into another select statement

i try to get the product_category from " SELECT product_category from sales_view where customerno = 12100"

and apply into "SELECT product_name from products where product _category = " product category from above.

im using c# ADO.NET.
ASKER CERTIFIED SOLUTION
Avatar of ralmada
ralmada
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
try using this one select statment
select distinct products.product_name from products join sales_view on product._category = sales_view.product_category where sales_view.customerno = 12100

Open in new window

If you want to use join use alias:
select a.product_name 
from products a
inner join sales_view b on a.product_category = b.product_category
where a.customerno = 12100

Open in new window

Avatar of mabbj747
mabbj747

If SELECT product_category from sales_view where customerno = 12100 query is always returning only single result then you can use the query using "=" operator using the nested query else use "IN".
SELECT PRODUCT_NAME FROM PRODUCTS WHERE PRODUCT_CATEGORY LIKE (SELECT PRODUCT_CATEGORY FROM SALES_VIEW WHERE CUSTOMERNO=12100) ABC


ABC is just the name of inner (sub) query.