Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/56.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 - Fatal编程技术网

MySql由两列组成的组

MySql由两列组成的组,mysql,Mysql,我刚刚开始学习php的mysql!我在使用查询mysql从表中获取数据时遇到问题 我有一张有田地的桌子 表名(团队) 像这样的数据表(团队) **id** **OPPONENT** **COMPETITION** 1 barcelona real madrid 2 barcelona Villarreal 3 real madrid ruby 我希望写查询得到这样的表 **

我刚刚开始学习php的mysql!我在使用查询mysql从表中获取数据时遇到问题 我有一张有田地的桌子 表名(团队)

像这样的数据表(团队)

**id**  **OPPONENT**    **COMPETITION**
     1      barcelona         real madrid 
     2      barcelona         Villarreal   
     3      real madrid       ruby
我希望写查询得到这样的表

 **team**
 barcelona
 Villarreal
 real madrid 
 ruby   

这个表应该有您的团队的外键,您只需在teams表中选择teams name

无论如何,如果您想这样做,请尝试以下方法:

SELECT DISTINCT opponent AS team FROM table
UNION
SELECT DISTINCT competition AS team FROM table
SELECT DISTINCT t.opponent team FROM (
    SELECT opponent team
    FROM tbl
    UNIOUN ALL
    SELECT competition team
    FROM tbl
) t
SELECT DISTINCT opponent AS team FROM table
UNION
SELECT DISTINCT competition AS team FROM table