开发者

MYSQL: Select from all tables in a DB

So I have a DB called files and it contains 3 tables (IMG,FLASH,PDF)... how would I run a query on them all a开发者_运维百科nd and return everything inside them as a single array?


If you have the same field in your tables, you can UNION the results:

SELECT content
FROM IMG
UNION ALL
SELECT content
FROM FLASH
UNION ALL
SELECT content
FROM PDF


do they all have exactly the same column set?

if so you could do a UNION

if not, then you will need to issue 3 queries...


You may be interested by the MySQL MERGE storage engine if your 3 tables have identical structures. If not just use UNION and use aliases if your columns don't have the same names.

SELECT commonColumn1, commonColumn2
FROM IMG
UNION ALL
SELECT commonColumn1, commonColumn2
FROM FLASH
UNION ALL
SELECT commonColumn1, notSoCommonColumn2 AS commonColumn2
FROM PDF
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜