user41549
user41549

Reputation: 7

does not display a particular id in mysql

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

Answers (3)

Theraot
Theraot

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

fortegente
fortegente

Reputation: 1391

Try the next:

$tampil= mysql_query("SELECT comments,nama,kota,jwb FROM user where id NOT IN ('49', '50')");

Upvotes: 2

Mr. Alien
Mr. Alien

Reputation: 157314

Use OR and <> where <> means NOT EQUAL

SELECT comments, nama, kota, jwb FROM user WHERE id <> '49' OR id <> '50'

Upvotes: 1

Related Questions