RE: How do you make an IN span multiple tables?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Have you tried using an 'OR' operator?

SELECT
	*
FROM
	table1,
	table2,
	table3
WHERE
	table1.threadref IN (1,2,3,4,5) OR
	table2.threadref IN (1,2,3,4,5) OR
	table3.threadref IN (1,2,3,4,5)

--Nicole
---------------------------
Nicole Swan
Web Programming Specialist
Carroll College CCIT
(406)447-4310

-----Original Message-----
From: Richard Davey [mailto:rich@xxxxxxxxxxxxxxxx]
Sent: Thursday, March 04, 2004 7:36 AM
To: php-db
Subject: Spam: How do you make an IN span multiple tables?


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

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux