JumpIntoTheWater
JumpIntoTheWater

Reputation: 1336

SQL Query result is wrong

I have a view (A) which contains 9 rows when running the following query :

SELECT *
FROM A
WHERE card_num_full is null OR card_num_full LIKE ''

Table B does not contain these 9 rows, so why when running the following query , I'm still getting 9 rows as a result?

SELECT *
FROM A
WHERE card_num_full is null OR card_num_full LIKE ''
      AND field_1 IN   
        (SELECT field_1
         FROM B)

Upvotes: 1

Views: 68

Answers (2)

Pawel Czapski
Pawel Czapski

Reputation: 1864

You can use ISNULL() function, then no brackets needed.

SELECT * 
FROM A WHERE isnull(card_num_full,'') like ''  
    and field_1 in
        (select field_1 from B)

Upvotes: 1

JohnHC
JohnHC

Reputation: 11195

Bracket your or

SELECT * 
FROM A 
WHERE (card_num_full is null 
    or card_num_full like '')
and field_1 in (select field_1 from B)

Upvotes: 2

Related Questions