How do you make an IN span multiple tables?
| From: | Richard Davey | Date: | Thu, 04 Mar 2004 14:35:56 +0000 |
| Subject: | How do you make an IN span multiple tables? | ||
| Groups: | php.db | ||
| Request: | Send a blank email to php-db+get-33303@lists.php.net to get a copy of this message | ||
Hi,
I'm a bit stuck with the following: I need to select data from 3
different tables and want to do it via a SELECT ... IN query. Each
table has a primary key called thread_ref. I would like to do
something like this:
SELECT
*
FROM
table1,
table2,
table3
WHERE
thread_ref IN (1,2,3,4,5,6,7,8,9,10)
Now the problem is that MySQL complains about the thread_ref being
ambiguous - which I know that it is. But putting a table name in-front
of it will limit the IN query to that specific table and cause no
results to be returned.
It is possible that not all of the tables will contain all of the
thread_ref's in question.
Does anyone have any ideas or is it just not possible using this
method? I'm not using MySQL 4 otherwise I would have looked at using a
UNION.
--
Best regards,
Richard Davey
http://www.phpcommunity.org/wiki/296.html