How to Return Results with Integers and Nulls?

Asked

Viewed 44 times

1

I’m trying to build a Query but they’re not succeeding, in my database I have 28 information with code 32, and 62 information with code 23, but there is information with null code, and I wanted to bring them all together, the problem is that when I try to fetch the result by throwing the codes in the WHERE tag the query comes empty.

Example:

SELECT * FROM tabela WHERE campo IN (23, 32, NULL);

I tried that way too:

SELECT * FROM tabela WHERE campo IN (23, 32) AND campo IS NULL;

Someone would have a solution ?

  • SELECT * FROM tabela WHERE campo IN (23, 32) OR campo IS NULL, have tried?

  • Yes, in that case I only brought the nulls and I didn’t bring the fields with 23 and 32 together... I need you to bring the nulls and those with code 23 and 32.

1 answer

1


It was almost colleague, try it:

SELECT * FROM tabela WHERE campo IN (23, 32) OR campo IS NULL;
  • I only brought the nulls, I need you to return the nulls with code 23 and 32.

  • SELECT * FROM table WHERE field IN (23, 32) AND field IS NULL;

  • I tried again and it worked, Thanks Victo Zanella, thanks Marconi the query worked, was as follows: SELECT * FROM table WHERE field IN (23, 32) OR field IS NULL;

  • @Lucaslima, but what was the difference ?

  • I had typed wrong I forgot the IS had put only NULL, then I checked I was wrong compared to yours, and it worked.

  • iuehiuehiue, beauty

Show 1 more comment

Browser other questions tagged

You are not signed in. Login or sign up in order to post.