Search code examples
mysqlwhere-clauseexcept

Mysql Query Except and Where


I have the follow query selecting stuff from a database:

mysql_query("SELECT * FROM categories order by id desc EXCEPT 
             WHERE id = $post_id") 
or die(mysql_error());

What I want to do is select all the columns in the "category" table, order them by id descending except where the column "id" equals the variable $post_id.

However, this does not work. I'm relatively new to this sort of stuff so could you guys give me a pointer in the right direction? I'd really appreciate it.

Thanks!


Solution

  • try this instead:

    SELECT * FROM categories WHERE id != $post_id
    order by id desc 
    
    /* except = not equal */