Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/asp.net-mvc-3/4.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,我有两张桌子。就像 ----用户表-- ----名称表-- 如何在mysql中一次查询中获取所有数据(如姓名、父亲、母亲、自己的姓名)?为每个姓名连接一次名称表: select id, u.user, email, o.fullname own, f.fullname father, m.fullname mother from users u left join nametable o on o.userid = u.id and o.name = 'own' left join nameta

我有两张桌子。就像

----用户表--

----名称表--


如何在mysql中一次查询中获取所有数据(如姓名、父亲、母亲、自己的姓名)?

为每个姓名连接一次名称表:

select id, u.user, email, o.fullname own, f.fullname father, m.fullname mother
from users u
left join nametable o on o.userid = u.id and o.name = 'own'
left join nametable f on f.userid = u.id and f.name = 'father'
left join nametable m on m.userid = u.id and m.name = 'mother'

请注意名称表上的所有条件必须处于联接条件中,才能使联接保持外部联接。

为每个名称联接一次名称表:

select id, u.user, email, o.fullname own, f.fullname father, m.fullname mother
from users u
left join nametable o on o.userid = u.id and o.name = 'own'
left join nametable f on f.userid = u.id and f.name = 'father'
left join nametable m on m.userid = u.id and m.name = 'mother'

请注意,名称表上的所有条件都必须位于联接条件中,才能使联接保持为外部联接。

您必须使用多个联接。有人向我查询过吗?我是新来的,请给我一个示例查询。你必须使用多个连接。有人给我一个查询吗?我是新来的,请给我一个查询这个例子。
select id, u.user, email, o.fullname own, f.fullname father, m.fullname mother
from users u
left join nametable o on o.userid = u.id and o.name = 'own'
left join nametable f on f.userid = u.id and f.name = 'father'
left join nametable m on m.userid = u.id and m.name = 'mother'