[英]MYSQL SELECT only one column from all rows in table
I need to select all values from all rows by one column in my table. 我需要从表中的每一列中选择所有行中的所有值。 I have
我有
ID TAGS
1 girls, womens, cars
2 girls, world, flowers
3 weapons, cars, boys
so after SQL I should get an array: 所以在SQL之后,我应该得到一个数组:
array('girls', 'womens', 'cars', 'girls', 'world', 'flowers', 'weapons', 'cars', 'boys')
so how my sql should look like? 所以我的sql应该是什么样子?
Like you see now this will only give you headaches. 就像您现在看到的那样,这只会让您头痛。 Normalize your table.
标准化表格。
USER_ID TAG
1 girls
1 women
1 cars
2 girls
...
After that you could select your desired result like this 之后,您可以像这样选择所需的结果
select group_concat(distinct tag)
from your_table
Use GROUP_CONCAT() . 使用GROUP_CONCAT() 。 A similar answer is already here MySQL DISTINCT on a GROUP_CONCAT() .
MySQL DISTINCT在GROUP_CONCAT()上已经有一个类似的答案。
I can atleast give a sample solution: 我可以至少提供一个示例解决方案:
someone can put these example and make a solution. 有人可以举这些例子并提出解决方案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.