0 votes
1 view
in SQL by (37.1k points)

Can anyone tell me how to write subquery in SQL?

1 Answer

0 votes
by (89.6k points)

The subquery is a normal query nested inside another query. Here is the basic syntax to use subquery with IN operator:

SELECT column_names

FROM table_name1

WHERE value IN (SELECT column_name

                               FROM table_name2

                               WHERE condition)

For example, if you want to list the product details with orders quantities greater than 100.

SELECT Product_Name

FROM Product_table

 WHERE Id IN (SELECT Product_Id

                          FROM OrderItem_table

                          WHERE Quantity > 100)

You can check out this SQL Tutorial blog learns subqueries and writing complex sub-queries.

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...