[英]distinct multiple columns in SQL
I want to select distinct
combination of user age
(a column name) and user name
(another column name) , but when I write distinct (user_age, user_name)
, there is syntax error
. 我想选择
user age
(一个列名)和user name
(另一个列名)的distinct
组合,但是当我写distinct (user_age, user_name)
,出现syntax error
。 If anyone have ideas how to write distinct
with multiple columns
it will be great. 如果有人对如何在
multiple columns
写出distinct
有想法,那就太好了。
BTW, using MySQL Workbench/MySQL
顺便说一句,使用
MySQL Workbench/MySQL
thanks in advance, Lin 预先感谢林
You have to leave the parenthesis. 您必须离开括号。 Just write
写吧
SELECT distinct user_age, user_name FROM foo where bar;
;-) ;-)
There are 2 ways to achieve this 有两种方法可以实现此目的
SELECT DISTINCT user_age, user_name FROM table WHERE some_condition;
OR 要么
SELECT user_age, user_name FROM table WHERE some_condition GROUP BY user_age, user_name;
Hope this helps 希望这可以帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.