Sql in operator sub query
Using SQL in operator with subquery example
sample example table name product_table
and in table column names example
id, product_id, product _naem, product_price, account_id, .....ect.
using a subquery to return the prices of the products in selected values.
sample example query:
- select product_name, product_price FROM product_table WHERE id IN ( select id FROM product_table WHERE account_id = 1 ) ORDER BY product_name;
- explanation :
- first, the subquery returned a list of product ids.
- Second, the outer query retrieved the product name and product prices