sql表别名的用法:as
http://www.w3school.com.cn/sql/sql_alias.asp
select * from kettleoutputtable a
where a.os =2 and storename = 'anzhi'
和
select * from kettleoutputtable as a
where a.os =2 and storename = 'anzhi'
等效,也就是说别名的as可以省略!在表明后直接加上简单的名字就行了。
去除重复记录的经典小例子:
假设现有一张人员表(表名:Person),若想将姓名、身份证号、住址这三个字段完全相同的记录查找出来,使用:
1: SELECT p1.*
2: FROM persons p1,persons p2
3: WHERE p1.id<>p2.id
4: AND p1.cardid = p2.cardid
5: AND p1.pname = p2.pname
6: AND p1.address = p2.address
注意,在表明后,有没有as 都行。
或者,如下去重
查数据:
select * from table1 a
where rowid !=(select max(rowid)
from table1 b where a.name1=b.name1 and a.name2=b.name2......)
删数据:
delete from table1 a
where rowid !=(select max(rowid)
from table1 b where a.name1=b.name1 and a.name2=b.name2......)