MySQL Logical Operators
时间:2008-09-25 来源:bj2008_0201
Logical Operators
One of the great features within MySQL is its full support for logical operations. I will name off, and show examples of them below
mysql> CREATE TABLE users (
-> id INT NOT NULL AUTO_INCREMENT,
-> name VARCHAR (50),
-> email VARCHAR (50),
-> PRIMARY KEY (id));
NOT (or) !
mysql> SELECT * FROM users WHERE
-> (name != "Blair Ireland");
or
mysql> SELECT * FROM users WHERE
-> (name NOT = "Blair Ireland");
This query would return all records without Blair Ireland present as the name.
AND (or) &&
mysql> SELECT * FROM users WHERE
mysql> (name = "Blair Ireland") AND mysql> (email = "[email protected]");
or
mysql> SELECT * FROM users WHERE
-> (name = "Blair Ireland") &&
-> (email = "[email protected]");
This query would return all records with Blair Ireland present as the name, and [email protected] as the email.
OR ( or ) ||
mysql> SELECT * FROM test WHERE
-> (name = "Blair Ireland") OR
-> (email = "[email protected]");
or
mysql> SELECT * FROM test WHERE
-> (name = "Blair Ireland") ||
-> (email = "[email protected]");
This query would return all records with Blair Ireland present as the name, or records with [email protected] as the email.