You are using MySQL < 5 correct? If so, this should speed things up quite a bit:
SELECT p.id, t.id2
FROM table1 p
LEFT JOIN table2 t
ON t.id2 = p.id1
WHERE p.time > 1135012444
AND p.id = t.col3
UNION
SELECT p.id, t.id2
FROM table1 p
LEFT JOIN table2 t
ON t.id2 = p.id1
WHERE p.id IN (<array>)
AND p.id = t.col3;
however, I have trouble understanding how correct results are returned for the second, since I cannot think of a situation where the following will be true:
p.id IN (<array>) *and* p.id = t.col3
unless, of course, t.col3 is actually in the array... so, you can shorten to:
SELECT p.id, t.id2
FROM table1 p
LEFT JOIN table2 t
ON t.id2 = p.id1
WHERE p.time > 1135012444
AND p.id = t.col3
UNION
SELECT p.id, t.id2
FROM table1 p
LEFT JOIN table2 t
ON t.id2 = p.id1
WHERE p.id = t.col3;
Jay Pipes
Community Relations Manager, North America, MySQL Inc.
Got Cluster?
http://www.mysql.com/cluster
Personal:
http://jpipes.com
Edited 1 time(s). Last edit at 12/19/2005 08:48PM by Jay Pipes.