SQL Query Examples
Find the SQL query you need with practical examples for common use cases. Each query includes explanations, variants, and pro tips.
Popular SQL Queries
How to Calculate Date Difference in SQL
Calculate the difference between two dates in days, months, or years.
How to Compare Current Row with Previous in SQL
Access previous or next row values using LAG and LEAD window functions.
How to Concatenate Strings in SQL
Combine multiple strings or columns into one using CONCAT or || operator.
How to Count Rows in SQL
Count the total number of rows in a table using COUNT() or COUNT(column).
How to Count Rows in SQL in SQL
Count the total number of rows in a table using COUNT() or COUNT(column).
How to Delete Duplicate Rows in SQL
Remove duplicate records while keeping one copy using CTEs and ROW_NUMBER.
How to Filter NULL Values in SQL
Handle NULL values using IS NULL, IS NOT NULL, and COALESCE.
How to Find Duplicate Records in SQL
Identify duplicate rows in a table using GROUP BY and HAVING.
How to Get Second Highest Value in SQL
Find the second highest salary or value using subquery or LIMIT OFFSET.
How to Join Two Tables in SQL
Combine data from multiple tables using INNER JOIN, LEFT JOIN, or RIGHT JOIN.
How to Rank Rows in SQL
Assign rankings using ROW_NUMBER, RANK, or DENSE_RANK window functions.
How to Select Top N Rows in SQL
Retrieve the first N rows from a result set using LIMIT, TOP, or FETCH.
Aggregation
Data Quality
Joins
Ranking
Window Functions
Other
Can't find what you're looking for?
Try our interactive SQL sandbox to experiment with your own queries.
Open SQL Sandbox