SQL SQL MOC


The WHERE command can filter results from a SELECT.

SELECT fields FROM tablename WHERE condition;

Conditions

The simplest condition is equality.

SELECT * FROM orders WHERE currency = "$" ORDER BY total ASC;

Linking Tables

An important condition is linking tables according to the primary and foreign key pair, which is similar to JOIN.

customerIdfirstNamelastNameaddresscitycountry
1UrsaVasquezP.O. Box 878, 8416 Nullam St.WorcesterUnited States
2QuynMeyerP.O. Box 670, 7155 Tincidunt St.PriceCanada
3OrliKlein4981 Gravida St.Barrow-in-FurnessUnited Kingdom
orderIddatecurrencytotalcustomerId
12020-11-14$1116
22020-07-07£9584
32021-02-18£7212
SELECT orders.orderId, customers.firstName, customers.lastName, orders.currency, orders.total
FROM orders, customers
WHERE orders.customerId = customers.customerId;