10 SQL Nested Queries
10 SQL Nested Queries
+----+---------------+----------+----------------+-------------+
| ID | NAME | AGE | ADDRESS | SALARY |
+----+----------------+----------+-----------------+------------+
| 1 | Ivan | 35 | Mumbai | 2000.00 |
| 2 | Mamta | 25 | Madras | 1500.00 |
| 3 | Chhaya | 23 | Mumbai | 2000.00 |
| 4 | Ashwini | 25 | Mumbai | 6500.00 |
| 5 | Hansel | 27 | Bangalore | 8500.00 |
| 6 | Deepak | 22 | Mangalore | 4500.00 |
| 7 | Vandana | 24 | Mumbai | 10000.00|
+-----+-----------------+------------+---------------+-------------+
SELECT * FROM CUSTOMERS
WHERE ID IN (SELECT ID FROM
CUSTOMERS WHERE SALARY > 4500) ;
+-----+----------+--------+-------------+----------+ |
| ID | NAME | AGE | ADDRESS | SALARY |
+------+----------+-------+-------------+----------+ |
| 4 | Ashwini | 25 | Mumbai | 6500.00 |
| 5 | Hansel | 27 | Bangalore | 8500.00 |
| 6 | Deepak | 22 | Mangalore | 4500.00 |
| 7 | Vandana | 24 | Mumbai | 10000.00|
+-----+-----------------+------------+---------------+-----|
Example
Find the non moving products,i.e.products not
being sold.
Select ProductNo,Description
From Product_Master
Where ProductNo NOT IN (select ProductNo
From Sales_order_details);
Example
Find the name and complete address for the
customer who has placed ordernumber
‘O19001’
Select
name,addrs1,adddrs2,city,State,Pincode
From Client_master
Where client_no IN(select client_no from
sales_order where orderno=‘O19001’
Example
Find the names of clients who have placed orders
worth 10000 and more.
Select name from client_master
where client_no IN(select client_no from
sales_order where orderno In
(select orderno from sales_order_details
where(Qtyordered*productRate)>=10000));