- 使用 DISTINCT 关键字:
SELECT DISTINCT column1, column2
FROM table_name;
- 使用 GROUP BY 子句:
SELECT column1, column2
FROM table_name
GROUP BY column1, column2;
- 使用窗口函数(ROW_NUMBER()):
WITH CTE AS (
SELECT column1, column2, ROW_NUMBER() OVER (PARTITION BY column1, column2 ORDER BY column1) AS rn
FROM table_name
)
SELECT column1, column2
FROM CTE
WHERE rn = 1;
- 使用临时表:
CREATE TABLE temp_table AS
SELECT DISTINCT column1, column2
FROM table_name;
SELECT * FROM temp_table;