Search code examples
mysqlexcept

MySQL except trying get all user that is online except one


How can I say in MySQL when I want to select all the typing and user that is online(1) except for one user with the id of 4? and I want the username of id= 4 not the typing

I tried NOT IN but I'm guessing it is not working for me.

SELECT username,typing FROM members WHERE status = 1 NOT IN (SELECT typing FROM members WHERE id =4)

http://img266.imageshack.us/img266/2313/typing.png

click the image for more info


Solution

  • Is this what you want?

    SELECT username, 
           (case when id <> 4 then typing end) as typing
    FROM members
    WHERE status = 1 or id = 4
    

    Based on your image, I think you just want:

    SELECT username, typing
    FROM members
    WHERE status = 1 and id <> 4