SQL Fundamentals

0.0(0)
Studied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/21

encourage image

There's no tags or description

Looks like no tags are added yet.

Last updated 1:00 PM on 10/7/26
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai
Chat

No analytics yet

Send a link to your students to track their progress

22 Terms

1
New cards

Show every column and every row in the orders table

SELECT * FROM orders;

2
New cards

Show only the customer and amount columns

SELECT customer, amount FROM orders;

3
New cards

Show orders where the city is Chicago

SELECT * FROM orders WHERE city = 'Chicago'; (text needs single quotes)

4
New cards

Show orders with an amount greater than 100

SELECT * FROM orders WHERE amount > 100; (numbers don't need quotes)

5
New cards

Show orders NOT from Chicago

SELECT * FROM orders WHERE city != 'Chicago'; (<> also works)

6
New cards

Show customers whose name starts with J

SELECT * FROM orders WHERE customer LIKE 'J%'; ('%J' = ends with J, '%J%' = contains J)

7
New cards

Show Chicago orders that are also over 50

SELECT * FROM orders WHERE city = 'Chicago' AND amount > 50;

8
New cards

Show orders with an amount from 20 to 50, including both

SELECT * FROM orders WHERE amount BETWEEN 20 AND 50; (BETWEEN is inclusive)

9
New cards

Show orders from Chicago or Denver

SELECT * FROM orders WHERE city = 'Chicago' OR city = 'Denver'; (repeat the column name)

10
New cards

Shorter way to show orders from Chicago, Denver, or Austin

SELECT * FROM orders WHERE city IN ('Chicago', 'Denver', 'Austin');

11
New cards

Sort orders from biggest amount to smallest

SELECT * FROM orders ORDER BY amount DESC; (default is ascending)

12
New cards

Show only the 3 biggest orders

SELECT * FROM orders ORDER BY amount DESC LIMIT 3; (LIMIT goes last)

13
New cards

How many orders are in the table?

SELECT COUNT(*) FROM orders;

14
New cards

What's the total of all order amounts?

SELECT SUM(amount) FROM orders;

15
New cards

Find the single largest order amount

SELECT MAX(amount) FROM orders; (MIN = smallest, AVG = average)

16
New cards

Show each customer and their total spent

SELECT customer, SUM(amount) FROM orders GROUP BY customer;

17
New cards

Show customers whose total spent is over 100

SELECT customer, SUM(amount) FROM orders GROUP BY customer HAVING SUM(amount) > 100;

18
New cards

Difference between WHERE and HAVING

WHERE filters rows before grouping. HAVING filters groups after GROUP BY and can use SUM, COUNT, etc.

19
New cards

Add a new order: Sam bought a lamp for 40 in Denver

INSERT INTO orders (customer, product, amount, city) VALUES ('Sam', 'lamp', 40, 'Denver');

20
New cards

Change order #7's amount to 55

UPDATE orders SET amount = 55 WHERE id = 7; (no WHERE = every row changes!)

21
New cards

What does DELETE FROM orders; do with no WHERE?

Deletes every row. The empty table still exists.

22
New cards

Correct clause order in a query

SELECT, FROM, WHERE, GROUP BY, HAVING, ORDER BY, LIMIT (Some Funny Wizards Grow Huge Orange Lemons)