Rats... itchy fingers on the send button...

On Jun 11, 2005, at 12:32 PM, Puneet Kishor wrote:

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?


My question stems from my understanding that I can convert the first SELECT into a VIEW and then conveniently SELECT against that VIEW.

CREATE VIEW bigview AS (
        SELECT * FROM ((SELECT * FROM tbl1) UNION (SELECT * FROM tbl2))
)

SELECT * FROM bigview WHERE b = 'foo'

But, that will be slow, no?

--
Puneet Kishor

Reply via email to