Loading subject…
Item while the person who made it sits in Artist.NULL.SELECT table1.column1, table2.column2FROM table1JOIN table2 ON table1.common_column = table2.common_column;SELECT Item.ItemID, Item.ItemDesc, Artist.ArtistNameFROM ItemJOIN Artist ON Item.ArtistID = Artist.ArtistID;Item.ItemID, removes any ambiguity when both tables have a column of the same name.SELECT * returns every column, which is convenient when exploring data but wasteful in a real query.SELECT DISTINCT Artist.ArtistNameFROM ItemJOIN Artist ON Item.ArtistID = Artist.ArtistID;WHERE and ON need to decide whether to keep a row.| Operator | Meaning | Example condition |
|---|---|---|
| = | Equal to | ItemCost = 250 |
| <> or != | Not equal to | Country <> 'Italy' |
| < | Less than | ItemCost < 100 |
| <= | Less than or equal to | ItemCost <= 100 |
| > | Greater than | PurchaseDate > '2025-07-28' |
| >= | Greater than or equal to | Quantity >= 2 |
=, not the double == used in Java and Python.Country = Italy fails while Country = 'Italy' works.ItemCost BETWEEN 100 AND 300 is the same as ItemCost >= 100 AND ItemCost <= 300.% wildcard to stand for any run of characters, including none.'Cer%' matches names starting with Cer, '%ics' matches names ending in ics.'%Ceramics%' matches the word anywhere in the value, which is how a search box is usually built.Items costing 100 to 300 inclusive, excluding anything by a ceramics studio:
SELECT Item.ItemDesc, Artist.ArtistNameFROM ItemJOIN Artist ON Item.ArtistID = Artist.ArtistIDWHERE Item.ItemCost BETWEEN 100 AND 300AND NOT Artist.ArtistName LIKE '%Ceramics%';Country = 'Italy' OR Country = 'France' AND Quantity > 2 does not do what it looks like.(Country = 'Italy' OR Country = 'France') AND Quantity > 2 to apply the quantity test to both countries.ASC for ascending or DESC for descending.COUNT, which returns how many rows fell into each group.SELECT Artist.ArtistName, COUNT(Item.ItemID) AS ItemCountFROM ItemJOIN Artist ON Item.ArtistID = Artist.ArtistIDGROUP BY Artist.ArtistNameHAVING COUNT(Item.ItemID) = 2ORDER BY Artist.ArtistName ASC;Customer and their orders in Purchase, linked by CustomerID.SELECT Customer.CustomerName, COUNT(Purchase.ItemID) AS OrdersFROM PurchaseJOIN Customer ON Purchase.CustomerID = Customer.CustomerIDWHERE (Customer.Country = 'Italy' OR Customer.Country = 'France')AND Purchase.PurchaseDate BETWEEN '2025-07-28' AND '2025-07-31'GROUP BY Customer.CustomerNameORDER BY Orders DESC;