我正在使用以下联合查询与左连接查询
(SELECT id as hotspots_id,location as town,gmlat,gmlng,street,country,zipcode as
plz,name,description ,c.id as cat_id ,c.* FROM `jos_skopelos_pages_list` LEFT JOIN
`jos_skopelos_listcategories` AS c ON jos_skopelos_pages_list.type=cat_id WHERE
published = 1) UNION ALL (SELECT id as hotspots_id,location as
town,gmlat,gmlng,street,country,zipcode as plz,name,description ,c.id as cat_id ,c.* FROM
`jos_skopelos_accomodation` LEFT JOIN `jos_skopelos_listcategories` AS c ON
jos_skopelos_accomodation.type=cat_id WHERE published = 1) UNION ALL (SELECT id as
hotspots_id,location as town,gmlat,gmlng,street,country,zipcode as plz,name,description
,c.id as cat_id ,c.* FROM `jos_skopelos_entertainment` LEFT JOIN
`jos_skopelos_listcategories` AS c ON jos_skopelos_entertainment.type=cat_id WHERE
published = 1) UNION ALL (SELECT id as hotspots_id,location as
town,gmlat,gmlng,street,country,zipcode as plz,name,description ,c.id as cat_id ,c.*
FROM `jos_skopelos_realstate` LEFT JOIN `jos_skopelos_listcategories` AS c ON
jos_skopelos_realstate.type=cat_id WHERE published = 1)
上面的查询是带有union语句的工作文件但是当我添加左连接语句时,它给出错误“#1052 - 字段列表中的列'id'是不明确的。”请记住当我删除左连接时表“jos_skopelos_listcategories”我的查询工作正常,但当我添加左连接语句时,它给出了上述错误请帮助
答案 0 :(得分:0)
我认为对于所有这些人,您需要更清楚地定义列,特别是因为id位于您要连接在一起的两个表中。例如,第一行更改,id为jos_skopelos_pages_list.id。在最后一节中,将id更改为jos_skopelos_realstate.id以及中间的所有联合。另外,当您说LEFT JOIN jos_skopelos_listcategories AS c
时,您只需撰写LEFT JOIN jos_skopelos_listcategories c