Reputation: 7
I would like to not display the id 49 and 50. I've been using the following query but it did not work
$tampil= mysql_query("SELECT comments,nama,kota,jwb FROM user where id='49','50'");
Upvotes: 0
Views: 275
Reputation: 40140
You said (Emphasis mine):
I would like to not display the id 49 and 50.
if you want to NOT show those ids... then you need to skip on them, like so:
SELECT comments, nama, kota, jwb FROM user WHERE id <> '49' AND id <> '50'
Emphasis on AND. Notice that if - for example - id
is 49
then id <> '49'
will be FALSE
but id <> '50'
will be TRUE
.. and FALSE OR TURE
is TRUE
, leaving it pass. Instead you want to use AND
because FALSE AND TURE
is FALSE
making sure that id will not appear.
For more clarity use NOT IN (as fortegente's answer):
SELECT comments, nama, kota, jwb FROM user WHERE id NOT IN ('49', '50')
For the opposite effect, just apply De Morgan's law:
SELECT comments, nama, kota, jwb FROM user WHERE id = '49' OR id = '50'
Or...
SELECT comments, nama, kota, jwb FROM user WHERE id IN ('49', '50')
Note: I hope to clear confusion for the casual reader (really I bet some people don't read, I wonder why I care to write).
Upvotes: 0
Reputation: 1391
Try the next:
$tampil= mysql_query("SELECT comments,nama,kota,jwb FROM user where id NOT IN ('49', '50')");
Upvotes: 2
Reputation: 157314
Use OR
and <>
where <>
means NOT EQUAL
SELECT comments, nama, kota, jwb FROM user WHERE id <> '49' OR id <> '50'
Upvotes: 1