Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql 如何选择两个唯一字段的结果并显示为结果的一列?_Mysql_Sql - Fatal编程技术网

Mysql 如何选择两个唯一字段的结果并显示为结果的一列?

Mysql 如何选择两个唯一字段的结果并显示为结果的一列?,mysql,sql,Mysql,Sql,我有两个字段include和excludes,我想提取其中唯一的数据,并将结果显示为结果的一列。 例如,包含和排除具有相同的可能值,如午餐、晚餐、wifi。结果应该是,, 排除和包括 排除和包含之间的唯一结果 ..................... 午餐 晚餐 无线网络 etc您可以使用union: 您可以这样编写查询: select DISTINCT x.excludesAndIncludes from (select DISTINCT excludes as excludesAndInc

我有两个字段include和excludes,我想提取其中唯一的数据,并将结果显示为结果的一列。 例如,包含和排除具有相同的可能值,如午餐、晚餐、wifi。结果应该是,, 排除和包括 排除和包含之间的唯一结果 ..................... 午餐 晚餐 无线网络 etc

您可以使用union:


您可以这样编写查询:

select DISTINCT x.excludesAndIncludes from
(select DISTINCT excludes as excludesAndIncludes from t
union
select DISTINCT includes as excludesAndIncludes from t) as x;

请提供样本数据和预期结果。包括:晚餐、wifi、午餐不包括:晚餐、wifi、午餐、早餐预期结果:包括和排除:wifi、午餐、早餐、晚餐可能有效。如果这样做有效的话,我会把这个标记为正确答案。@kartik。这将返回一个唯一的值列表,这就是问题所要求的:排除和包含之间的唯一结果。
select DISTINCT x.excludesAndIncludes from
(select DISTINCT excludes as excludesAndIncludes from t
union
select DISTINCT includes as excludesAndIncludes from t) as x;