tbl1(a INTEGER PRIMARY KEY, b VARCHAR(200) UNIQUE) with 200k+ records
tbl2(a INTEGER PRIMARY KEY, b VARCHAR(200) UNIQUE) with a few k records
values in col(b) in tbl1 are not common with the values in col(b) in
tbl2
I want to find a given string in either tbl1 or tbl2. Which of the
following is better?
SELECT *
FROM ((SELECT * FROM tbl1) UNION (SELECT * FROM tbl2))
WHERE b = 'foo'
or
SELECT * FROM tbl1 WHERE b = 'foo'
UNION
SELECT * FROM tbl1 WHERE b = 'foo'
In my experience, the first SELECT is much slower, but are there any
gotchas with the second SELECT? Is there a better way?
--
Puneet Kishor