SELECT first_name || ' ' || last_name AS full_name
FROM users;String concatenation syntax varies by dialect; CONCAT() is also widely available.
Reference for string, date, numeric, conditional, null-handling, and aggregate SQL functions.
Transform and search text values.
SELECT first_name || ' ' || last_name AS full_name
FROM users;String concatenation syntax varies by dialect; CONCAT() is also widely available.
SELECT UPPER(email) AS email_upper, LOWER(email) AS email_lower
FROM users;Useful for case-insensitive comparisons and normalized reporting.
SELECT TRIM(name) AS cleaned_name
FROM customers;LTRIM and RTRIM are also available in many engines.
SELECT SUBSTRING(phone FROM 1 FOR 3) AS area_code
FROM contacts;Substring function syntax differs slightly across SQL dialects.
SELECT REPLACE(phone, '-', '') AS digits_only
FROM contacts;Handy for lightweight normalization.
Work with dates, timestamps, and intervals.
SELECT CURRENT_DATE AS today, CURRENT_TIMESTAMP AS now_ts;These values are useful for auditing and reporting queries.
SELECT
EXTRACT(YEAR FROM created_at) AS year_num,
EXTRACT(MONTH FROM created_at) AS month_num
FROM orders;Useful for grouping and reporting by calendar parts.
SELECT created_at, created_at + INTERVAL '7 days' AS plus_seven_days
FROM orders;Interval syntax varies slightly across engines.
SELECT CAST(created_at AS DATE) AS created_date
FROM orders;Useful for daily rollups.
CASE, COALESCE, NULLIF, CAST, and type-safe expressions.
SELECT order_id,
CASE
WHEN amount >= 1000 THEN 'large'
WHEN amount >= 100 THEN 'medium'
ELSE 'small'
END AS bucket
FROM orders;CASE is one of the most useful SQL expressions for reporting and categorization.
SELECT COALESCE(phone, mobile_phone, 'N/A') AS preferred_phone
FROM contacts;COALESCE is portable and common across SQL engines.
SELECT revenue / NULLIF(order_count, 0) AS revenue_per_order
FROM daily_metrics;NULLIF is often used to avoid divide-by-zero errors.
SELECT CAST(total AS DECIMAL(12,2)) AS total_decimal
FROM invoices;Explicit casts make query intent clearer and avoid implicit conversion surprises.
Conditional aggregation and distinct counting.
SELECT COUNT(DISTINCT customer_id) AS unique_customers
FROM orders;Distinct counts are common in analytics and business reporting.
SELECT
COUNT(*) AS total_orders,
SUM(CASE WHEN status = 'paid' THEN 1 ELSE 0 END) AS paid_orders,
SUM(CASE WHEN status = 'refunded' THEN 1 ELSE 0 END) AS refunded_orders
FROM orders;CASE inside aggregates is a staple reporting pattern.
SELECT CAST(created_at AS DATE) AS day, COUNT(*) AS total
FROM events
GROUP BY CAST(created_at AS DATE)
ORDER BY day;Very common for dashboards and time-series summaries.