listout checklist of sql query
listout checklist of sql query
SELECT Statement:
Retrieve data from a table.
SELECT column1, column2 FROM table_name;
WHERE Clause:
Filter data based on a condition.
SELECT column1, column2 FROM table_name WHERE condition;
ORDER BY Clause:
Sort the result set.
SELECT column1, column2 FROM table_name ORDER BY column1 ASC;
SELECT with LIMIT:
SELECT column1, column2 FROM table_name LIMIT 10;
Aggregate Function - COUNT:
SELECT COUNT(*) FROM table_name;
SELECT SUM(column1) FROM table_name;
SELECT SUM(column1) FROM table_name;
Aggregate Function - AVG:
SELECT AVG(column1) FROM table_name;
Aggregate Function - MAX:
SELECT MAX(column1) FROM table_name;
Aggregate Function - MIN:
SELECT MIN(column1) FROM table_name;
GROUP BY Clause:
Group rows that have the same values in specified columns.
SELECT column1, COUNT(*) FROM table_name GROUP BY column1;
HAVING Clause:
Filter results of the GROUP BY clause.
SELECT column1, COUNT(*) FROM table_name GROUP BY column1 HAVING COUNT(*) > 1;
INSERT Statement:
Add new records to a table.
INSERT INTO table_name (column1, column2) VALUES (value1, value2);
UPDATE Statement:
Modify existing records in a table.
UPDATE table_name SET column1 = value1 WHERE condition;
DELETE Statement:
Remove records from a table.
DELETE FROM table_name WHERE condition;
JOIN Clause:
Combine rows from two or more tables based on a related column.
SELECT t1.column1, t2.column2 FROM table1 t1 JOIN table2 t2 ON t1.id = t2.id;
INNER JOIN:
Return only the rows that have matching values in both tables.
SELECT t1.column1, t2.column2 FROM table1 t1 INNER JOIN table2 t2 ON t1.id = t2.id;
LEFT JOIN:
Return all rows from the left table and the matched rows from the right table.
SELECT t1.column1, t2.column2 FROM table1 t1 LEFT JOIN table2 t2 ON t1.id = t2.id;
RIGHT JOIN:
Return all rows from the right table and the matched rows from the left table.
SELECT t1.column1, t2.column2 FROM table1 t1 RIGHT JOIN table2 t2 ON t1.id = t2.id;
FULL OUTER JOIN:
Return all rows when there is a match in either the left or right table.
SELECT t1.column1, t2.column2 FROM table1 t1 FULL OUTER JOIN table2 t2 ON t1.id = t2.id;
UNION Operator:
Combine the results of two or more SELECT statements.
SELECT column1 FROM table1 UNION SELECT column1 FROM table2;
Subquery:
Use the result of one query in another query.
SELECT column1 FROM table1 WHERE column2 IN (SELECT column2 FROM table2 WHERE condition);
Aggregate Functions:
Perform calculations on a set of values.
SELECT AVG(column1), COUNT(column2), MAX(column3) FROM table_name;
Alias:
Rename a column or table using an alias.
SELECT column1 AS alias_name FROM table_name;
INDEX:
Create an index on a column to improve query performance.
CREATE INDEX index_name ON table_name (column1);
Transaction:
Execute a series of SQL statements as a single unit.
BEGIN TRANSACTION;
-- SQL statements
COMMIT;
GRANT and REVOKE:
Manage permissions.
GRANT SELECT, INSERT ON table_name TO user_name;
REVOKE UPDATE ON table_name FROM user_name;
Remember that syntax and features can vary between database systems, so it's always a good idea to refer to the specific documentation for the DBMS you are using.
Top comments (0)