mysql

mysql select去重的五种方法

小樊
144
2024-06-25 09:24:30
栏目: 云计算

  1. 使用DISTINCT关键字

SELECT DISTINCT column_name FROM table_name;

  1. 使用GROUP BY子句

SELECT column_name FROM table_name GROUP BY column_name;

  1. 使用子查询

SELECT column_name FROM table_name WHERE column_name IN (SELECT DISTINCT column_name FROM table_name);

  1. 使用HAVING子句

SELECT column_name FROM table_name GROUP BY column_name HAVING COUNT(column_name) = 1;

  1. 使用临时表

CREATE TEMPORARY TABLE temp_table AS SELECT DISTINCT column_name FROM table_name; SELECT * FROM temp_table;

0
看了该问题的人还看了