Search code examples
mysqlwhere-in

how to select both true and false column value in mysql


I'm having a table called file_download. I need to display

  1. downloaded file list - select * from file_download where downloaded = 1;
  2. not downloaded file list - select * from file_download where downloaded = 0;
  3. all file list - for all file list, what kind of condition has to mention?

below is the sample table.

+----+----------+---------+------------+
| pk | filename |  file   | downloaded |
+----+----------+---------+------------+
|  1 | aaa.txt  | aaa.txt |          1 |
|  2 | bbb.txt  | aaa.txt |          1 |
|  3 | ccc.txt  | aaa.txt |          0 |
|  4 | ccc.txt  | aaa.txt |          1 |
|  5 | ccc.txt  | aaa.txt |          0 |
|  6 | ccc.txt  | aaa.txt |          0 |
+----+----------+---------+------------+

Thanks in advance...


Solution

  • There are three ways to do the same

    Using OR (cheaper in cost)

    select * from file_download where downloaded = 1 or downloaded = 0

    Using IN (short and accurate way)

    select * from file_download where downloaded in (0, 1);

    Using is not null (way not recommended)

    select * from file_download where downloaded is not null