Chinaunix首页 | 论坛 | 博客
  • 博客访问: 196236
  • 博文数量: 37
  • 博客积分: 1390
  • 博客等级: 中尉
  • 技术积分: 336
  • 用 户 组: 普通用户
  • 注册时间: 2008-07-16 13:18
文章分类

全部博文(37)

文章存档

2011年(1)

2008年(36)

我的朋友

分类: Mysql/postgreSQL

2008-09-25 14:23:18


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 = "bireland@domainname.com");

or

mysql> SELECT * FROM users WHERE
-> (name = "Blair Ireland") &&
-> (email = "bireland@domainname.com");

This query would return all records with Blair Ireland present as the name, and bireland@domainname.com as the email.

OR ( or ) ||

mysql> SELECT * FROM test WHERE
-> (name = "Blair Ireland") OR
-> (email = "bireland@domainname.com");

or

mysql> SELECT * FROM test WHERE
-> (name = "Blair Ireland") ||
-> (email = "bireland@domainname.com");

This query would return all records with Blair Ireland present as the name, or records with bireland@domainname.com as the email.

阅读(1551) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~