TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   MySQL & Databases (http://www.talkphp.com/mysql-databases/)
-   -   SQL code...if NOT.... (http://www.talkphp.com/mysql-databases/4092-sql-code-if-not.html)

allworknoplay 04-02-2009 10:04 PM

SQL code...if NOT....
 
Ok, is there any way to make this query better? It seems like I should be able to somehow use less "AND"...



Code:

SELECT * FROM users WHERE user_id != '5' AND user_id != '6' AND user_id != '9' AND user_id != '3';

Salathe 04-02-2009 10:50 PM

First, why are you wrapping integers in quotes? Second, and more to the point, to use less (no!) ANDs you could use …WHERE user_id NOT IN (5, 6, 9, 3)

allworknoplay 04-02-2009 10:56 PM

Quote:

Originally Posted by Salathe (Post 22683)
First, why are you wrapping integers in quotes? Second, and more to the point, to use less (no!) ANDs you could use …WHERE user_id NOT IN (5, 6, 9, 3)

Thank you!!

Yes I suppose using quotes turns the numbers into strings right?
Or is that just a PHP thing?

Salathe 04-02-2009 11:08 PM

Yes, it's just more work for the MySQL engine to do as I assume your user_id values are integers.

allworknoplay 04-02-2009 11:16 PM

Quote:

Originally Posted by Salathe (Post 22685)
Yes, it's just more work for the MySQL engine to do as I assume your user_id values are integers.

thanks, yes they are of "INT" value....

I will have to keep this in mind...

^^


All times are GMT. The time now is 01:23 PM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0