对于像这样的查询
$query = "
SELECT t1.title, t1.content, t2.image, t2.tags
FROM blog1posts t1, blog1imagestags t2
WHERE id = :id
UNION ALL
SELECT t1.title, t1.content, t2.image, t2.tags
FROM blog2posts t1, blog2imagestags t2
WHERE id = :id
UNION ALL //THE PROBLEM
SELECT t1.title, t1.content, t2.tags
FROM blog2posts t1, blog3imagestags t2
WHERE id = :id
";
我如何使用查询联合或加入最后一部分?
答案 0 :(得分:2)
你可以尝试这个(在第三个UNION中添加一个虚拟字段):
SELECT t1.title, t1.content, t2.image, t2.tags
FROM blog1posts t1, blog1imagestags t2
WHERE id = :id
UNION ALL
SELECT t1.title, t1.content, t2.image, t2.tags
FROM blog2posts t1, blog2imagestags t2
WHERE id = :id
UNION ALL
SELECT t1.title, t1.content, '' AS image, t2.tags
FROM blog2posts t1, blog3imagestags t2
WHERE id = :id