数据库的各种连接查询你是否真了解

来源:未知 责任编辑:责任编辑 发表时间:2014-05-26 11:02 点击:

数据库的各种连接查询你是否真了解
 
下面就让我们来做个小测试,一一探查常用数据库的连接原理。
--数据测试环境准备:
SQL> create table t1(a int);
 
Table created
SQL> create table t2(b int);
 
Table created
SQL> insert into t1 values(1);
 
1 row inserted
SQL> insert into t1 values(2);
 
1 row inserted
SQL> insert into t1 values(3);
 
1 row inserted
SQL> insert into t2 values(1);
   www.2cto.com  
1 row inserted
SQL> insert into t2 values(2);
 
1 row inserted
SQL> insert into t2 values(4);
 
1 row inserted
 
SQL> commit;
 
Commit complete
 
--内连接,符合条件的行列出,可以看作是两个表的交集
SQL> select t1.*,t2.* from t1 inner join t2 on t1.a=t2.b;
 
                                      A                                       B
--------------------------------------- ---------------------------------------
                                      1                                       1
                                      2                                       2
 
--交叉连接,即返回两个表的笛卡尔积
SQL> select t1.*,t2.* from t1 cross join t2;
                                      A                                       B
--------------------------------------- ---------------------------------------
                                      1                                       1
                                      1                                       2
发表评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
用户名: 验证码:点击我更换图片
最新评论 更多>>

推荐热点

  • Request.ServerVariables 参数大全
  • 执行全文索引时出现权限不足的解决方法
  • 导入excel文件处理流程节点的解决方案
  • 查看sql修改痕迹(SQL Change Tracking on Table)
  • App数据层设计及云存储使用指南
  • PostgreSQL启动过程中的那些事三:加载GUC参数
  • MongoDB安装为Windows服务方法与注意事项
  • Percolator与分布式事务思考(二)
  • 写给MongoDB开发者的50条建议Tip1
网站首页 - 友情链接 - 网站地图 - TAG标签 - RSS订阅 - 内容搜索
Copyright © 2008-2015 计算机技术学习交流网. 版权所有

豫ICP备11007008号-1