0

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'");

3 Answers 3

2

Try the next:

$tampil= mysql_query("SELECT comments,nama,kota,jwb FROM user where id NOT IN ('49', '50')");
Sign up to request clarification or add additional context in comments.

Comments

1

Use OR and <> where <> means NOT EQUAL

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

Comments

0

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).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.