SELECT column1, column2 FROM table_name;
SELECT * FROM table_name;
SELECT * FROM table_name WHERE condition;
例如:
SELECT * FROM employees WHERE age > 30;
SELECT DISTINCT column_name FROM table_name;
SELECT COUNT(column_name) FROM table_name;
SELECT MAX(column_name) FROM table_name;
SELECT MIN(column_name) FROM table_name;
SELECT AVG(column_name) FROM table_name;
SELECT SUM(column_name) FROM table_name;
SELECT * FROM table_name ORDER BY column_name ASC|DESC;
例如:
SELECT * FROM employees ORDER BY salary DESC;
SELECT column1, COUNT(column2) FROM table_name GROUP BY column1;
SELECT * FROM table1 INNER JOIN table2 ON table1.column_name = table2.column_name;
SELECT * FROM table1 LEFT JOIN table2 ON table1.column_name = table2.column_name;
SELECT * FROM table1 RIGHT JOIN table2 ON table1.column_name = table2.column_name;
SELECT * FROM table1 FULL OUTER JOIN table2 ON table1.column_name = table2.column_name;
SELECT column_name(s) FROM table_name WHERE column_name OPERATOR (SELECT column_name FROM table_name WHERE condition);
SELECT * FROM table_name LIMIT offset, count;
例如:
SELECT * FROM employees LIMIT 5, 10; -- 跳过前5条记录,返回接下来的10条记录
使用 UNION
或 UNION ALL
(UNION ALL
会包括重复的行):
SELECT column_name(s) FROM table1
UNION
SELECT column_name(s) FROM table2;
这些只是一些基本的示例。SQL 查询可以根据需要变得非常复杂和强大,包括使用子查询、多表连接、复杂的条件和函数等。