santyas
santyas

Reputation: 96

Select all where values equal 1?

It is the best way to select only records with "1" value? I cant make it works :/

$results = mysqli_query($connecDB,"SELECT * FROM codes WHERE php = 1 AND java = 1 AND ruby = 1 ORDER BY id ASC");

+------+----------------+---------+--------+--------+
| ID   | CODES          |   PHP   |  RUBY  |  JAVA  |
+------+----------------+---------+--------+--------+
| 1    | ford           |    1    |    0   |    0   |
+------+----------------+---------+--------+--------+
| 2    | seat           |    1    |    1   |    1   |
+------+----------------+---------+--------+--------+
| 3    | fiat           |    1    |    1   |    0   |
+------+----------------+---------+--------+--------+
| 4    | toyota         |    1    |    0   |    0   |
+------+----------------+---------+--------+--------+
| 5    | chevrolete     |    1    |    0   |    1   |
+------+----------------+---------+--------+--------+

Upvotes: 0

Views: 1092

Answers (2)

Mr. Alien
Mr. Alien

Reputation: 157314

Your query won't work if your column is not an int so wrap the quotes around the values and try

$results = mysqli_query($connecDB,"SELECT * FROM codes 
           WHERE php = '1' AND java = '1' AND ruby = '1' ORDER BY id ASC");

Upvotes: 1

abhinsit
abhinsit

Reputation: 3272

SELECT codes FROM table_name WHERE php = 1 AND java = 1

The condition can be concatenated using AND/Or as pr required

Upvotes: 0

Related Questions