mssql查询(高级).docVIP

  • 42
  • 0
  • 约1.22万字
  • 约 13页
  • 2018-04-05 发布于浙江
  • 举报
mssql查询(高级)

1.UNION,EXCEPT,INTERSECT运算符 A,UNION 运算符 UNION 运算符通过组合其他两个效果表(例如 TABLE1 和 TABLE2)并消去表中任何重复行而派生出一个效果表。 当 ALL 随 UNION 一起运用时(即 UNION ALL),不消除重复行。两种情况下,派生表的每一行不是来自 TABLE1 便是来自 TABLE2。 B, EXCEPT 运算符 EXCEPT 运算符通过包含全部在 TABLE1 中但不在 TABLE2 中的行并消除全部重复行而派生出一个效果表。 当 ALL 随 EXCEPT 一起运用时 EXCEPT ALL ,不消除重复行。 C,INTERSECT 运算符 INTERSECT 运算符通过只包含 TABLE1 和 TABLE2 中都有的行并消除全部重复行而派生出一个效果表。 当 ALL 随 INTERSECT 一起运用时 INTERSECT ALL ,不消除重复行。 注:运用运算词的几个查询效果行有必要是一起的。 2.外联接 A、left outer join: 左外联接(左联接):效果集几包含联接表的匹配行,也包含左联接表的全部行。 sql: select a.a, a.b, a.c, b.c, b.d, b.f from a LEFT OUT JOIN b ON a.a b.c B:right outer join: 右外联接 右联接 :效果集既包含联接表的匹配联接行,也包含右联接表的全部行。 C:full outer join: 全外联接:不只包含符号联接表的匹配行,还包含两个联接表中的全部记载。 其次,我们来看一些不错的sql语句 1、说明:拷贝表 只拷贝规划,源表名:a 新表名:b Access可用 法一:select * into b from a where 1 1 法二:select top 0 * into b from a 2、说明:仿制表 仿制数据,源表名:a 政策表名:b Access可用 insert into b a, b, c select d,e,f from b; 3、说明: 跨数据库之间表的仿制 具体数据运用绝对路径 Access可用 insert into b a, b, c select d,e,f from b in ‘具体数据库’ where 条件 比如:..from b in Server.MapPath . \data.mdb where.. 4、说明:子查询 表名1:a 表名2:b select a,b,c from a where a IN select d from b 或许: select a,b,c from a where a IN 1,2,3 5、说明:闪现文章、提交人和结束回复时辰 select a.title,a.username,b.adddate from table a, select max adddate adddate from table where table.title a.title b 6、说明:外联接查询 表名1:a 表名2:b select a.a, a.b, a.c, b.c, b.d, b.f from a LEFT OUT JOIN b ON a.a b.c 7、说明:在线视图查询 表名1:a select * from SELECT a,b,c FROM a T where t.a 1; 8、说明:between的用法,between捆绑查询数据规划时包含了距离值,not between不包含 select * from table1 where time between time1 and time2 select a,b,c, from table1 where a not between 数值1 and 数值2 9、说明:in 的运用办法 select * from table1 where a [not] in ‘值1’,’值2’,’值4’,’值6’ 10、说明:两张关联表,删去主表中已经在副表中没有的信息 delete from table1 where not exists select * from table2 where table1.field1 table2.field1 11、说明:四表联查疑问: select * from a left inner join b on a.a b.b right inner join c on a.a c.c inner join d on a.a d.d where

文档评论(0)

1亿VIP精品文档

相关文档