Tables and Select
Where and Order
Filtering Rows
WHERE keeps rows that match a condition. ORDER BY sorts the remaining rows.
Program
Play the script to filter in-stock products and sort by price.
where_order.sql
CREATE TABLE products (name TEXT, price INTEGER, stock INTEGER);
INSERT INTO products VALUES ('pen', 3, 10), ('bag', 25, 0), ('book', 12, 4);
SELECT name, price FROM products WHERE stock > 0 ORDER BY price;
WHERE
`WHERE stock > 0` keeps only rows with available stock.
comparison
`>` compares each row's value.
sort
`ORDER BY price` sorts the filtered rows.