- 使用DISTINCT关键字
SELECT DISTINCT column_name FROM table_name;
- 使用GROUP BY子句
SELECT column_name FROM table_name GROUP BY column_name;
- 使用子查询
SELECT column_name FROM table_name WHERE column_name IN (SELECT DISTINCT column_name FROM table_name);
- 使用HAVING子句
SELECT column_name FROM table_name GROUP BY column_name HAVING COUNT(column_name) = 1;
- 使用临时表
CREATE TEMPORARY TABLE temp_table AS SELECT DISTINCT column_name FROM table_name; SELECT * FROM temp_table;