[英]finding all of different values in a column of a mysql table
i have a mysql table like this : 我有一个像这样的mysql表:
+------+-------------+----------+
| id | name | category |
+------+-------------+----------+
| 1 | product 1 |category-A|
| 2 | product 2 |category-B|
| 3 | product 3 |category-C|
| 4 | product 4 |category-B|
| 5 | product 5 |category-C|
| 6 | product 6 |category-A|
| 7 | product 7 |category-A|
| 8 | product 8 |category-C|
| 9 | product 9 |category-B|
+------+-------------+----------+
is there any function that returns sth like this? 有没有返回像这样的功能?
category-A,category-B,category-C
note : new categories may be added later . 注意:以后可能会添加新类别。
thanks . 谢谢 。
SELECT GROUP_CONCAT(DISTINCT category ORDER BY category) FROM TableName
OUTPUT 输出值
╔══════════════════════════════════╗
║ RESULT ║
╠══════════════════════════════════╣
║ category-A,category-B,category-C ║
╚══════════════════════════════════╝
Use DISTINCT
in your query, it eliminate duplicate entry 在查询中使用
DISTINCT
,可避免重复输入
SELECT GROUP_CONCAT(DISTINCT category )
FROM your_table
Are you just looking for a unique list of all categories? 您是否正在寻找所有类别的唯一列表?
SELECT DISTINCT category FROM mytable 从mytable中选择DISTINCT类别
Try 尝试
SELECT DISTINCT columnName FROM table_name SELECT DISTINCT columnName FROM table_name
This should give you result containing all different values from that column. 这应该为您提供包含该列中所有不同值的结果。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.