SQL 中不同的多列
distinct multiple columns in SQL
我想 select distinct
user age
(一个列名)和 user name
(另一个列名)的组合,但是当我写 distinct (user_age, user_name)
,有syntax error
。如果有人知道如何用 multiple columns
编写 distinct
那就太好了。
顺便说一句,使用 MySQL Workbench/MySQL
提前致谢,
林
你必须离开括号。只写
SELECT distinct user_age, user_name FROM foo where bar;
;-)
有两种方法可以做到这一点
SELECT DISTINCT user_age, user_name FROM table WHERE some_condition;
或
SELECT user_age, user_name FROM table WHERE some_condition GROUP BY user_age, user_name;
希望对您有所帮助
我想 select distinct
user age
(一个列名)和 user name
(另一个列名)的组合,但是当我写 distinct (user_age, user_name)
,有syntax error
。如果有人知道如何用 multiple columns
编写 distinct
那就太好了。
顺便说一句,使用 MySQL Workbench/MySQL
提前致谢, 林
你必须离开括号。只写
SELECT distinct user_age, user_name FROM foo where bar;
;-)
有两种方法可以做到这一点
SELECT DISTINCT user_age, user_name FROM table WHERE some_condition;
或
SELECT user_age, user_name FROM table WHERE some_condition GROUP BY user_age, user_name;
希望对您有所帮助