我正在尝试使用php和mysql数据库做类似的事情:
SELECT * FROM accomodation,assessment,beneficiaries,site
FROM accomodation,assessment,beneficiaries,site
WHERE ITS_Code != "none"
ITS_Code
在所有表格之间是相互的
谢谢
答案 0 :(得分:1)
您可以使用加入
SELECT a.*, b.*, c.*, d.*
FROM accomodation as a
LEFT Join assessment as b on a.ITS_Code = b.ITS_Code
LEFT JOIN beneficiaries as c on a.ITS_Code = c.ITS_Code
LEFT JOIN site as d on a.ITS_Code = d.ITS_Code
WHERE a.ITS_Code != "none"
答案 1 :(得分:0)
假设表格住宿,评估,受益人和网站具有相同数量的列,并且您我只是想连续列出每个表的内容,你可以这样做:
SELECT Column1, Column2, Column3 FROM accomodation
WHERE ITS_code <> "none"
UNION ALL
SELECT Column1, Column2, Column3 FROM assessment
WHERE ITS_code <> "none"
UNION ALL
SELECT Column1, Column2, Column3 FROM beneficiaries
WHERE ITS_code <> "none"
UNION ALL
SELECT Column1, Column2, Column3 FROM site
WHERE ITS_code <> "none"
如果其中一个表格的列数不等 - 例如网站只有2列 - 那么您可以SELECT NULL
取代它,例如:
SELECT Column1, Column2, Column3 FROM accomodation
WHERE ITS_code <> "none"
UNION ALL
SELECT Column1, Column2, Column3 FROM assessment
WHERE ITS_code <> "none"
UNION ALL
SELECT Column1, Column2, Column3 FROM beneficiaries
WHERE ITS_code <> "none"
UNION ALL
SELECT Column1, Column2, NULL AS Column3 FROM site
WHERE ITS_code <> "none"