Debug School

rakesh kumar
rakesh kumar

Posted on

listout the checklist of sql query

listout checklist of sql query

listout checklist of sql query

SELECT Statement:

Retrieve data from a table.

SELECT column1, column2 FROM table_name;
Enter fullscreen mode Exit fullscreen mode

WHERE Clause:

Filter data based on a condition.

SELECT column1, column2 FROM table_name WHERE condition;
Enter fullscreen mode Exit fullscreen mode

ORDER BY Clause:

Sort the result set.

SELECT column1, column2 FROM table_name ORDER BY column1 ASC;
Enter fullscreen mode Exit fullscreen mode

SELECT with LIMIT:

SELECT column1, column2 FROM table_name LIMIT 10;
Enter fullscreen mode Exit fullscreen mode

Aggregate Function - COUNT:

SELECT COUNT(*) FROM table_name;
Enter fullscreen mode Exit fullscreen mode
SELECT SUM(column1) FROM table_name;
Enter fullscreen mode Exit fullscreen mode

SELECT SUM(column1) FROM table_name;
Aggregate Function - AVG:

SELECT AVG(column1) FROM table_name;
Enter fullscreen mode Exit fullscreen mode

Aggregate Function - MAX:

SELECT MAX(column1) FROM table_name;
Enter fullscreen mode Exit fullscreen mode

Aggregate Function - MIN:

SELECT MIN(column1) FROM table_name;
Enter fullscreen mode Exit fullscreen mode

GROUP BY Clause:

Group rows that have the same values in specified columns.

SELECT column1, COUNT(*) FROM table_name GROUP BY column1;
Enter fullscreen mode Exit fullscreen mode

HAVING Clause:

Filter results of the GROUP BY clause.

SELECT column1, COUNT(*) FROM table_name GROUP BY column1 HAVING COUNT(*) > 1;
Enter fullscreen mode Exit fullscreen mode

INSERT Statement:

Add new records to a table.

INSERT INTO table_name (column1, column2) VALUES (value1, value2);
Enter fullscreen mode Exit fullscreen mode

UPDATE Statement:

Modify existing records in a table.

UPDATE table_name SET column1 = value1 WHERE condition;
Enter fullscreen mode Exit fullscreen mode

DELETE Statement:

Remove records from a table.

DELETE FROM table_name WHERE condition;
Enter fullscreen mode Exit fullscreen mode

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;
Enter fullscreen mode Exit fullscreen mode

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;
Enter fullscreen mode Exit fullscreen mode

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;
Enter fullscreen mode Exit fullscreen mode

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;
Enter fullscreen mode Exit fullscreen mode

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;
Enter fullscreen mode Exit fullscreen mode

UNION Operator:

Combine the results of two or more SELECT statements.

SELECT column1 FROM table1 UNION SELECT column1 FROM table2;
Enter fullscreen mode Exit fullscreen mode

Subquery:

Use the result of one query in another query.

SELECT column1 FROM table1 WHERE column2 IN (SELECT column2 FROM table2 WHERE condition);
Enter fullscreen mode Exit fullscreen mode

Aggregate Functions:

Perform calculations on a set of values.

SELECT AVG(column1), COUNT(column2), MAX(column3) FROM table_name;
Enter fullscreen mode Exit fullscreen mode

Alias:

Rename a column or table using an alias.

SELECT column1 AS alias_name FROM table_name;
Enter fullscreen mode Exit fullscreen mode

INDEX:

Create an index on a column to improve query performance.

CREATE INDEX index_name ON table_name (column1);
Enter fullscreen mode Exit fullscreen mode

Transaction:

Execute a series of SQL statements as a single unit.

BEGIN TRANSACTION;
-- SQL statements
COMMIT;
Enter fullscreen mode Exit fullscreen mode

GRANT and REVOKE:

Manage permissions.

GRANT SELECT, INSERT ON table_name TO user_name;
REVOKE UPDATE ON table_name FROM user_name;
Enter fullscreen mode Exit fullscreen mode

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)