George Reith
George Reith

Reputation: 13476

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 and and return everything inside them as a single array?

Upvotes: 0

Views: 1262

Answers (3)

Alin P.
Alin P.

Reputation: 44386

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

Upvotes: 0

Cyril Gandon
Cyril Gandon

Reputation: 17068

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

Upvotes: 2

Randy
Randy

Reputation: 16673

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...

Upvotes: 0

Related Questions