Do not display null lines in mysql results

Asked

Viewed 829 times

0

I have a simple mysql query

SELECT usr_contact FROM $usr_

I use PDO to connect this table has lines that have empty fields thus

-----------------------
|   id    |usr_contact|
-----------------------
|  1234   |    null   |
-----------------------
|  null   |   147852  |

in consultation he creates

contact
---
X
---
147852

how do I not display empty fields in the result?

  • 2

    SELECT * FROM tabela WHERE campo IS NOT NULL the null id O.o?

  • 1

    @rray "AutoIncrementProgramming"?

  • @rray does not serve, if I put it SELECT * FROM table WHERE id IS NOT NULL it only brings the null information, if I put SELECT * FROM table WHERE usr_contact IS NOT NULL it brings everything even the nulls

  • 1

    yes, id null because I am creating a different database that does not need the ids because they will all be the same id

  • A OR would not solve or has more column to check?

  • in fact, will have many lines with empty values, phone book example, has name displays, has no name does not display, this I wish to do, it does not display the lines I do not ask, ie only display the lines with name but not with empty name

  • When I did the field, I didn’t set it as a NULL standard

  • Have you tried using left Join? See if this helps you: http://answall.com/questions/116937/left-join-repetir-tabelas/116950#116950

  • then @Diego the error doi in the little piece, forgot to put null in the table, is now working the is not null, but thanks.

Show 4 more comments
No answers

Browser other questions tagged

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