我有5个表,我希望从所有链接到名为pubs的表中获取数据。
special_offers有3条与酒吧相关的记录 events有4条与pub相关的记录
但是我只回来了第一个事件和special_offers。它似乎没有结构化为多级数组。我尝试过加入和内心联系,我看不出可能出现的问题。
SELECT pubs.*, special_offers.*, `events`.*, vote.*
FROM pubs
Inner Join `events`
ON pubs.id = `events`.pubID
Inner Join special_offers
ON pubs.id = special_offers.pubID
Inner Join vote
ON pubs.id = vote.pubID
WHERE pubs.id = 48
这是print_r的输出
Array (
[0] => 48
[id] => 1 Harveys
[name] => Harveys
[sun] => 10am-2.30am
[31] => 1
[32] => 4
[special_dayID] => 4
[33] => 48
[pubID] => 48
[34] => 2.50 Drinks
[title] => Kodakid
[35] => All drink 2.50 get them while there hot! or cold!
[desc] => Kodakid are playing!
[36] => 1
[37] => 48
[38] => 2012-04-30
[date] => 2012-04-30
[39] => Kodakid
[40] => & others
[subtitle] => & others
[41] => Kodakid are playing!
[42] => kodakid.jpg
[img] => kodakid.jpg
[43] => 1
[44] => 48
[45] => 3
[price_range] => 3
[46] => 5
[atmosphere] => 5
[47] => 2
[food] => 2
[48] => 4
[service] => 4
[49] => 3
[value] => 3
[50] => Waterford City
[county] => Waterford City )
由于
答案 0 :(得分:1)
你是如何进行实际查询的? MySQL不支持嵌套数组或行。结果集由零个或多个行组成,每行包含一个或多个数字,字符串,日期等。
您正在做的是要求包含所有四个表中所有列的结果集。因为您正在使用INNER联接,所以您要求MySQL仅返回所有四个表中存在的行。因此pubs
中events
中没有相关行的ID将不会包含在结果集中,即使它在其他两个行中也有行。
要做你要求的事情,你可以使用单独的查询(一个用于事件,一个用于投票等等)。您也可以尝试使用LEFT JOIN而不是INNER JOIN或子查询和聚合器(如GROUP_CONCAT),但这实际上取决于您对信息的计划。