• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 194
  • Last Modified:

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.
0
doramail05
Asked:
doramail05
1 Solution
 
ralmadaCommented:
You could combine both queries like this:
 
SELECT product_name from products
where product _category in (SELECT product_category from sales_view where customerno = 12100)
0
 
gemailjCommented:
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

0
 
ralmadaCommented:
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

0
 
mabbj747Commented:
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".
0
 
Khalid Mehmood AwanCommented:
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.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now