Code Lab is in development. New lessons and improvements are on the way. Progress can be deleted.
Loading…
Code Lab is in development. New lessons and improvements are on the way. Progress can be deleted.
Loading…
Code Lab is in development. New lessons and improvements are on the way. Progress can be deleted.
SQL / POSTGRESQL / Learn / LESSON 05
AND requires both conditions, OR at least one, and NOT negates a condition. AND has higher precedence than OR: use parentheses to group alternatives. SQL uses AND rather than &&.
Small example:
SELECT name FROM products WHERE (category = 'books' OR category = 'home') AND stock > 0;
Working tables for this task. Grading also uses other datasets with the same schema.
| id | name | category | price | stock |
|---|---|---|---|---|
| 1 | Book Light | books | 12 | 8 |
| 2 | Bowl | home | 20 | 4 |
| 3 | Lamp | home | 30 | 2 |
| 4 | Notebook | books | 10 | 12 |
| 5 | Box | NULL | 5 | 0 |
| 6 | Book Ocean | books | 20 | 1 |
| 7 | Mug | home | 30 | 3 |
| 8 | Pen | books | 19.99 | 7 |
| 9 | Cable | tools | 20.01 | 5 |
| 10 | Clip | tools | 9.99 | 3 |
| 11 | Fan | home | 30.01 | 1 |
| 12 | Book Edge | books | 20.01 | 2 |
| id | name | city |
|---|---|---|
| 1 | Mira | Sofia |
| 2 | Niko | Varna |
| 3 | Iva | Sofia |
| 4 | Alex | NULL |
| 5 | Boris | Plovdiv |
| 6 | Lena | Burgas |
| id | customer_id | total |
|---|---|---|
| 1 | 1 | 20 |
| 2 | 1 | 30 |
| 3 | 2 | 10 |
| 4 | 3 | 0 |
| 5 | 6 | 40 |
Expected columns: name · row order is not required
Expected result (displayed data):
Loading…AND requires both conditions, OR at least one, and NOT negates a condition. AND has higher precedence than OR: use parentheses to group alternatives. SQL uses AND rather than &&.
QUERY STANDBY
›