Double WHERE NOT语句sql

I have this query:

$query = "SELECT pic_square,
                 name,
                 highest_score,
                 num_tries,
                 avg_total 
            FROM users 
       WHERE NOT played_game = '0' 
        ORDER BY avg_total DESC";

Where I select pic_square,name,highest_score,num_tries and avg_total FROM for all users that

DO NOT have their played game set as ''0''.


I would like to add another condition so I select only the users that:

  • DO NOT have their played_game set as ''0''
  • DO NOT have their name empty

PS: The name cannot be null, it just can be empty, I cannot change the DB structure itself.

So how do I add these dual WHERE NOT together?

WHERE NOT (played_game = '0' or name = '')

or

WHERE played_game <> '0' and name <> ''
$query = "SELECT pic_square,name,highest_score,num_tries,avg_total FROM users 
  WHERE NOT (played_game = '0' OR name IS NULL OR name='' ) 
  ORDER BY avg_total DESC";
$query = "SELECT pic_square,name,highest_score,num_tries,avg_total FROM users 
  WHERE played_game <> '0' AND name <> ''  ORDER BY avg_total DESC";

simply change condition like

where played_game <> '0' AND name <> ''

You can use this query:

$query = "SELECT pic_square,
                 name,
                 highest_score,
                 num_tries,
                 avg_total 
            FROM users 
           WHERE NOT played_game = '0' 
             AND IFNULL(name,'') <> ''
        ORDER BY avg_total DESC";

Using IFNULL you'll get sure that NULL values and empty values are treated just the same.

$query = "SELECT pic_square,name,highest_score,num_tries,avg_total 
          FROM users 
          WHERE played_game != '0' 
            AND name NOT NULL 
          ORDER BY avg_total DESC";