SELECT <kolom1>, <kolom2> FROM <tabel1> WHERE <kolom3> IN ( SELECT <kolom4> FROM <tabel2> WHERE <kolom5> IN ( SELECT <kolom6> FROM <tabel3> WHERE <kolom7> = "Waarde" ));
SELECT <kolom01>, <kolom02> FROM <tabel01> WHERE <kolom02> IN ( SELECT MAX(kolom03) FROM <tabel02> );
Geef het product id en de product prijs van het duurste product
-- Oracle / MySQL / SQL Server SELECT prod_id, prod_price FROM Products WHERE prod_price IN ( SELECT MAX(prod_price) FROM Products );
prod_id | prod_price |
BR03 | 11.99 |
Selecteer de product id, productnaam en product prijs van de producten die meer kosten dan de gemiddelde productprijs
-- Oracle / MySQL / SQL Server SELECT prod_id, prod_name, prod_price FROM Products WHERE prod_price > ( SELECT AVG(prod_price) FROM Products ) ORDER BY prod_price;
prod_id | prod_name | prod_price |
BR02 | 12 inch teddy bear | 8.99 |
RYL01 | King doll | 9.49 |
RYL02 | Queen doll | 9.49 |
BR03 | 18 inch teddy bear | 11.99 |
Products.prod_id OrderItems.prod_id
SELECT <tabel1>.<kolom1>, <tabel1>.<kolom2>, ( SELECT COUNT(*) FROM <tabel2> WHERE <tabel2>.<kolom1> = <tabel1>.<kolom1> ) AS NieuweKolomNaam FROM <tabel1> ORDER BY <tabel1>.<kolom1>;
Selecteer de klantnaam en de klant staat(state) en hoeveel bestellingen de klant heeft gedaan
-- Oracle / MySQL / SQL Server SELECT Customers.cust_name, Customers.cust_state, ( SELECT COUNT(*) FROM Orders WHERE Orders.cust_id = Customers.cust_id ) AS orders FROM Customers ORDER BY Customers.cust_name;
cust_name | cust_state | orders |
Fun4All | IN | 1 |
Fun4All | AZ | 1 |
Kids Place | OH | 0 |
The Toy Store | IL | 1 |
Village Toys | MI | 2 |