Reputation: 599
I have a PDO Query which I am requesting the data of 5 identical tables from, I have tried a few ways of doing it, but can't seem to get any data back, the results just return empty.
SELECT * FROM
foo1, foo2, foo3, foo4, foo5
WHERE (
foo1.id OR foo2.id OR foo3.id OR foo4.id OR foo5.id
)
= ?
Am I missing something here? I found this question here PDO select from multiple identical tables but it didn't work for me either, there are definitely rows with the matching ID.
Upvotes: 0
Views: 26
Reputation: 5246
You need to query each table individually, then UNION ALL
the result:
SELECT *
FROM foo1
WHERE foo1.id = ?
UNION ALL
SELECT *
FROM foo2
WHERE foo2.id = ?
UNION ALL
...
This is essentially what PDO select from multiple identical tables is saying. However, as with the other question, you should really stop and think about why you need to have five separate identical tables.
Upvotes: 1