Skip to content
SQL

SELECT with WHERE and ORDER BY

Filter, sort, and limit rows with SELECT, WHERE, and ORDER BY in SQL.

#select#query#beginner

Code

sql
-- Basic SELECT with filtering and sorting
SELECT id, name, email, created_at
FROM users
WHERE status = 'active'
  AND age >= 18
ORDER BY created_at DESC
LIMIT 10 OFFSET 20;

-- Select distinct values
SELECT DISTINCT country
FROM users
ORDER BY country;

-- Column aliases and expressions
SELECT
  name,
  price * 1.2 AS price_with_tax,
  UPPER(name) AS name_upper
FROM products;