博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
mysql:联合查询
阅读量:7214 次
发布时间:2019-06-29

本文共 724 字,大约阅读时间需要 2 分钟。

SELECT t1.name, t2.salary  FROM employee AS t1 INNER JOIN info AS t2 ON t1.name = t2.name; 可以对数据表使用别名

select t1.id,t2.id
from t1
left join t2 on t1.id = t2.id and t1.id>1 and t2.id<>3

http://wenku.baidu.com/link?url=r-ks3kd0ZtGJtLW9vKq_B7kAEJtugvPaCV1NMitCesHi1DJWip50P44R6Ck076bDFyyKw1caIKpPyLP5yWympLGoqP25QHJN2A0sKHyhKLe

在mysql的left join中条件放在on后面和在where后面是不同的;

1. on后面只针对于t2表进行过滤,所以上面的t1.id>1将不起作用,切记,切记;

2. where后面会对最终结果产生影响,所以如果t2.id<>3放到on后面和where后面也是会返回不同的结果;

  例如下面脚本一会比脚本二多返回一些数据。

http://database.51cto.com/art/201011/234480.htm

select * from test2
left join test1 on test2.id = test1.id and test1.id<>3
where test2.id <>6;
select * from test2
left join test1 on test2.id = test1.id
where test2.id <>6 and test1.id<>3;

转载地址:http://jquym.baihongyu.com/

你可能感兴趣的文章
第一次实验
查看>>
Redis基础操作
查看>>
clob大数据转换为多行数据
查看>>
bootstrap的流式布局
查看>>
如何通过线程池异步调用
查看>>
Squid配置详解
查看>>
070104_微积分:随机变量及其分布(二项分布,均匀分布,正态分布)
查看>>
LeetCode – Refresh – Binary Tree Zigzag Level Order Traversal
查看>>
python操作三大主流数据库(13)python操作redis之新闻项目实战①新闻数据的导入
查看>>
2013夏,iDempiere来了 - v1.0c Installers (Devina LTS Release) 2013-06-27
查看>>
每天一个linux命令(22):find 命令的参数详解
查看>>
然后是几点(15)
查看>>
15.节点属性
查看>>
ISO-8859-1编码
查看>>
PHP 代码评审的 10 个提示
查看>>
你知道吗?Web的26项基本概念和技术
查看>>
方案优化:网站实现扫描二维码关注微信公众号,自动登陆网站并获取其信息...
查看>>
Leetcode | Balanced Binary Tree
查看>>
sqlServer对内存的管理
查看>>
挑战密室
查看>>