Retrieve all records from a table:
SELECT * FROM table_name;Retrieve specific columns from a table:
SELECT column1, column2 FROM table_name;Retrieve records with a specific condition:
SELECT * FROM table_name WHERE condition;Retrieve distinct values from a column:
SELECT DISTINCT column_name FROM table_name;Count the number of records in a table:
SELECT COUNT(*) FROM table_name;Retrieve records sorted in ascending order:
SELECT * FROM table_name ORDER BY column_name ASC;Retrieve records sorted in descending order:
SELECT * FROM table_name ORDER BY column_name DESC;Retrieve records using pattern matching (LIKE):
SELECT * FROM table_name WHERE column_name LIKE 'pattern';Retrieve records using wildcard characters (%):
SELECT * FROM table_name WHERE column_name LIKE 'pattern%';Retrieve records with NULL values:
SELECT * FROM table_name WHERE column_name IS NULL;Retrieve records between two dates:
SELECT * FROM table_name WHERE date_column BETWEEN 'start_date' AND 'end_date';Retrieve records from multiple tables (JOIN):
SELECT t1.column1, t2.column2
FROM table1 t1
INNER JOIN table2 t2 ON t1.key = t2.key;Retrieve aggregated data (GROUP BY):
SELECT column, COUNT(*)
FROM table_name
GROUP BY column;Retrieve aggregated data with conditions (HAVING):
SELECT column, COUNT(*)
FROM table_name
GROUP BY column
HAVING COUNT(*) > threshold;Insert a new record into a table:
INSERT INTO table_name (column1, column2) VALUES (value1, value2);Update records in a table:
UPDATE table_name SET column1 = new_value WHERE condition;Delete records from a table:
DELETE FROM table_name WHERE condition;Retrieve top N records from a table:
SELECT TOP N * FROM table_name;Retrieve records with pagination:
SELECT * FROM table_name LIMIT offset, limit;Retrieve records using subqueries:
SELECT * FROM table_name WHERE column IN (SELECT column FROM another_table WHERE condition);