Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/62.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/71.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,我有两张桌子 table1 id userid date_t game hdigit inside 1 yui 0909 alpha 8 700 2 loi 0809 beta 7 600 table2 id userid date_t game hdigit outside 1 yui 0909 alpha 8 600 2 ron 0809 gama 5 600 I

我有两张桌子

table1

id  userid date_t  game  hdigit inside
1   yui    0909    alpha 8      700
2   loi    0809    beta  7      600

table2

id  userid date_t  game  hdigit outside
1   yui    0909    alpha 8       600
2   ron    0809    gama  5      600

I want result like this

id  userid date_t  game  hdigit inside  outside
1   yui    0909    alpha 8      700      600
2   loi    0809    beta  7      600       null
3   ron    0809    gama  5      null      600
我试过简单连接

select table1.userid 
     , table1.date_t 
     , table1.game
     , table1.inside 
     , table2.outside 
  from table1 
     , table2 
 where table1.hdigit = table2.hdigit 
   AND table1.date_t = table2.date_t 
   AND table2.game = table1.game 
   AND table1.userid = table2.userid

很明显,这给了我一个简单的共同价值观连接,但是如何实现上述目标,任何帮助都将不胜感激。

出于您的目的,我认为
分组方式
/
联合所有
是最好的方法:

select (@rn := @rn + 1) as id, userid, date_t, game, hdigit,
       max(inside) as inside, max(outside) as outside
from ((select userid, date_t, game, hdigit, inside, null as outside
       from table1
      ) union all
      (select userid, date_t, game, hdigit, null, outside
       from table2
      )
     ) t cross join
     (select @rn := 0) params
group by userid, date_t, game, hdigit;

您不希望
完全联接的原因是,您似乎希望四键组合使用一行。当您需要一行时,
groupby
通常是可行的解决方案。

将逗号改为JOIN。将连接更改为左连接。把WHERE改为ON。我没有理解@strawberry,并注意到“3”在这个上下文中是没有意义的