CO1019: Databases and Web Applications: SQL Part 3: Subqueries and Multiple Tables Dr. Karim Mualla
CO1019: Databases and Web Applications: SQL Part 3: Subqueries and Multiple Tables Dr. Karim Mualla
Web Applications
SQL Part 3:
Subqueries and Multiple Tables
SELECT column_name(s)
FROM table_name
WHERE EXISTS
(SELECT column_name FROM table_name WHERE conditio
n);
SELECT SupplierName
FROM Suppliers
WHERE EXISTS (SELECT ProductName FROM Products WHERE Suppli
erId = Suppliers.supplierId AND Price < 20);
The following SQL statement returns TRUE and lists the suppliers with
a product price equal to 22:
SELECT SupplierName
FROM Suppliers
WHERE EXISTS (SELECT ProductName FROM Products WHERE Suppli
erId = Suppliers.supplierId AND Price = 22);
Client Viewing
ClientNo PropertyNo ViewDate Comment
ClientNo Fname Lname TelNo PrefType MaxRent CR56 PA14 24-May-01 too small
CR56 Aline Stewart 0141-848-1825 Flat 350 CR56 PG36 28-Apr-01
CR62 Mary Tregear 01224-196720 Flat 600
CR74 Mike Ritchie 01475-392178 House 750
CR56 PG4 26-May-01
CR76 John Kay 0207-774-5632 Flat 425
•LEFT JOIN: Return all rows from the left table, and the
matched rows from the right table
•RIGHT JOIN: Return all rows from the right table, and the
matched rows from the left table
The LEFT JOIN keyword returns all the rows from the left
table (Customers), even if there are no matches in the right
table (Orders).
Relationships
◦ 1-* relationships
◦ 1-1 relationships
◦ *-* relationships
CO1019 Databases and Web Applications 25
NATURAL JOIN