SELECT
The
SELECT
statement retrieves data from a database.
SELECT * FROM table_name; Find the syntax you need, copy an example, and get back to work.
No matching entries. Try another name or keyword.
The
SELECT
statement retrieves data from a database.
SELECT * FROM table_name; This query retrieves unique values from a specified column.
SELECT DISTINCT column_name FROM table_name;
The
WHERE
clause filters the results based on a specified condition.
SELECT * FROM table_name WHERE condition;
These operators are used to combine multiple conditions in a
WHERE
clause.
SELECT * FROM table_name WHERE condition1 AND/OR condition2;
ORDER BY
sorts the results in ascending (default) or descending order.
SELECT * FROM table_name ORDER BY column_name;
LIMIT
restricts the number of rows returned by a query.
SELECT * FROM table_name LIMIT n; This statement adds new records into a table.
INSERT INTO table_name (column1, column2, ...) VALUES (value1, value2, ...);
UPDATE
modifies existing records in a table.
UPDATE table_name SET column1 = value1, column2 = value2 WHERE condition;
The
DELETE
statement removes records from a table.
DELETE FROM table_name WHERE condition;
IN
allows you to specify multiple values in a
WHERE
clause.
SELECT * FROM table_name WHERE column_name IN (value1, value2, ...);
BETWEEN
filters results within a specified range.
SELECT * FROM table_name WHERE column_name BETWEEN value1 AND value2;
LIKE
is used for pattern matching.
SELECT * FROM table_name WHERE column_name LIKE pattern;
JOIN
combines records from two or more tables based on a related column.
SELECT * FROM table1 JOIN table2 ON table1.column = table2.column;
LEFT JOIN
retrieves all records from the left table and matching records from the right table.
SELECT * FROM table1 LEFT JOIN table2 ON table1.column = table2.column;
RIGHT JOIN
retrieves all records from the right table and matching records from the left table.
SELECT * FROM table1 RIGHT JOIN table2 ON table1.column = table2.column;
INNER JOIN
retrieves records with matching values in both tables.
SELECT * FROM table1 INNER JOIN table2 ON table1.column = table2.column;
GROUP BY
groups rows with the same values into summary rows.
SELECT column_name, COUNT(*) FROM table_name GROUP BY column_name;
HAVING
filters results of a
GROUP BY
query based on a condition.
SELECT column_name, COUNT(*) FROM table_name GROUP BY column_name HAVING condition;
COUNT
counts the number of records in a table.
SELECT COUNT(column_name) FROM table_name;
AVG
calculates the average value of a column.
SELECT AVG(column_name) FROM table_name;
MAX
and
MIN
retrieve the maximum and minimum values from a column, respectively.
SELECT MAX(column_name) FROM table_name;
SELECT MIN(column_name) FROM table_name;