我有一个MySQL表,其中包含以下类型的信息:
hop_id hop_1 hop_2 hop_3 hop_4..... hop_9 site_name hop_count
1 abc>aaa bcd>bbb zxc>ccc GPAC 3
2 bcd>bbb jkl>ddd abc>aaa pop>zoz SNKL 4
3 jkl>ddd zxc>ccc PBCL 2
我想从hop_1,hop_2,hop_3 ...... hop_9&中找到唯一值。打印它们。结果将是这样的。
hop
abc>aaa
bcd>bbb
zxc>ccc
jkl>ddd
pop>zoz
我使用distinct关键字,但它适用于一列,而不适用于所有列。我想打印为一个变量。请帮忙解决一下。提前谢谢。
答案 0 :(得分:0)
这应该有效
SELECT DISTINCT(x.keyword) FROM (
SELECT DISTINCT hop_1 as keyword FROM your table
UNION
SELECT DISTINCT hop_2 as keyword FROM your table
UNION
SELECT DISTINCT hop_3 as keyword FROM your table
....
SELECT DISTINCT hop_9 as keyword FROM your table) as x