【www.gdgbn.com--php与数据库】
sql 删除重复行(all或distinct)
/*
删除重复行select语句中使用all或distinct选项来显示表中符合条件的所有行或删除其中重复的数据行,默认为all。使用distinct选项时,对于所有重复的数据行在select返回的结果集合中只保留一行
我们也可以用它来去除重复的数据
合并两个表除去重复的数据(以表2的数据为主),我们将会得到以下的表:
a b
a 1
b 0
c 0
d 0
e 4
select a,b from 表1 where a not in(select a from 表2)
union
select a,b from 表2
//distinct语法
select distinct "栏位名" from "表格名"
//sql union all 语法
select column_name(s) from table_name1 union all select column_name(s) from table_name2