IN 操作符
IN 操作符允许您在where 子句中规定多个值
eg1: SELECT * from websites where name in ('Google','Facebook');
IN 与 = 的异同
eg1:SELECT * from websites where name='Google';
BETWEEN 操作符
eg1:SELECT * FROM websites where alexa BETWEEN 1 and 20;
eg2:SELECT * FROM websites where alexa NOT BETWEEN 1 and 20;
eg3:SELECT * FROM websites where (alexa BETWEEN 1 AND 20) AND NOT country IN ('USA','IND');
带有文本值的BETWEEN 操作符实力
eg4:SELECT * FROM websites where alexa BETWEEN A and H;
别名
不使用别名
select websites.name,websites.url,access_log.count,access_log.data
from websites,access_log
where websites.id=access_log.site_id and websites.name='Google';
使用别名
select w.name,w.url,a.count,a.data
from websties as w,access_log as a
where w.id=a.site_id and w.name='Google'
在下面的情况下,使用别名很有用:
- 在查询中涉及超过一个表
- 在查询中使用了函数
- 列名称很长或者可读性差
- 需要把两个列或者多个列结合在一起