Replacing a query with SELECT * FROM X WHERE Y is not NULL

Viewed 295

What does this query try to achieve?

SELECT * FROM X WHERE (X.Y in (select Y from X))

As far as I figured, it is yielding me the same result as

SELECT * FROM X WHERE Y is not NULL

Is there anything more to the first query? The first query is actually very slow with a large dataset and hence I want to know whether I can replace it with the second query.

2 Answers

You are right, the two queries are equivalent.

It is unclear, why the first query was written this way. Maybe it looked different once.

As is, your second query is better, because it is easier to read and understand (and even faster as you say).

your second query is perfect than the 1st one

because in 1st query you may get abnormal(null) result in case if column Y contains null value but you will not get abnormal result in 2nd one if null values contain in column Y.

So based on values of your table two query will behave two different way

Related