`

关于 FROM a,b 和 a LEFT JOIN b on 的区别 ...

 
阅读更多
SELECT * FROM a,b WHERE a.id=b.id

和 SELECT * FROM a LEFT JOIN b ON a.id=b.id

这两种写法有什么区别么 ...?

给个通俗的解释吧.
例表a
aid adate
1 a1
2 a2
3 a3
表b
bid bdate
1 b1
2 b2
4 b4
两个表a,b相连接,要取出id相同的字段
select * from a ,b where a.aid = b.bid这是仅取出匹配的数据.
此时的取出的是:
1 a1 b1
2 a2 b2
那么left join 指:
select * from a left join b on a.aid = b.bid
首先取出a表中所有数据,然后再加上与a,b匹配的的数据
此时的取出的是:
1 a1 b1
2 a2 b2
3 a3 空字符
同样的也有right join
指的是首先取出b表中所有数据,然后再加上与a,b匹配的的数据
此时的取出的是:
1 a1 b1
2 a2 b2
4 空字符 b4
 
分享到:
评论

相关推荐

    天思产品触发器

    update a set a.fs=a.kd*2/@spc from tf_pos_z a left join tf_pos c on a.os_no=c.os_no and a.itm=c.itm left join prdt b on c.prd_no=b.prd_no left join inserted d on a.os_no=d.os_no and a.itm=d.itm ...

    Web开发中常用的SQL语句

    Web开发中常用的SQL语句 说明:复制表(只复制结构,源表名:a 新表名:b) select * into b from a where 1<>1 说明:拷贝表(拷贝数据,...select a.a, a.b, a.c, b.c, b.d, b.f from a LEFT OUT JOIN b ON a.a = b.c

    mysql not in、left join、IS NULL、NOT EXISTS 效率问题记录

    NOT IN、JOIN、IS NULL、NOT EXISTS效率对比 语句一:select count(*) from A where A.a not in (select a from B) 语句二:select count(*) from A left join B on A.a = B.a where B.a is null 语句三:select ...

    解析sql语句中left_join、inner_join中的on与where的区别

    table a(id, type):id type ———————————-1 1 2 1 3 2 table b(id, class):id class ———————————1 12 2sql语句1:select a.*, b.* from a left join b on a.id = b.id and a.type = ...

    SQL高级面试题及答案

    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 7、在线视图查询(表名1:a ) select * from (SELECT a,b,c FROM a) T where t.a > 1;

    area.sql.txt

    学习sql练习使用CREATE TABLE IF NOT EXISTS `area` ( `id` int(11) unsigned NOT NULL, ...select * from area a left join area b on a.id=b.pid left join area c on b.id=c.pid having a.pid=0 order by a.id;

    sql中的left join及on、where条件关键字的区别详解

    LEFT JOIN 关键字会从左表 (table_name1) 那里返回所有的行,即使在右表 (table_name2) 中没有匹配的行。 LEFT JOIN 关键字语法 SELECT column_name(s) FROM table_name1 LEFT JOIN table_name2 ON table_name1....

    Sql Server中一个表2个字段关联同一个表(代码解决)

    代码如下:select a.man_id,man_name,d.sex_name,zw_name,c.money from man as a left join zw as b on a.zw_id=b.zw_id left join zw as c on a.man_id=c.man_id — 同时关联zw字段,通过表别名区别开 left ...

    SQL常用经典语句

    1、说明:复制表(只复制结构,源表名:a 新表名:b) (Access可用) 法一:select * into b from a where ...selecta.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 )

    mysql查询必练50题

    LEFT JOIN SC b ON b.cid=01 AND a.sid=b.sid LEFT JOIN SC c ON c.cid=02 AND a.sid=c.sid WHERE b.score>c.score; -- 2、查询平均成绩大于60分的同学的学号和平均成绩; SELECT sid 学号, AVG(score) 平均成绩...

    SQL技巧 常用SQL操作语句

    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 说明:日程安排提前五分钟提醒 SQL: select * from 日程安排 where datediff('minute',f开始时间,getdate())>5 说明:两张关联表...

    SQL LEFT JOIN 关键字

    SQL LEFT JOIN 关键字 SQL LEFT JOIN 关键字 LEFT JOIN 关键字从左表(table1)返回所有的行,即使右表(table2)中没有匹配。如果右表中没有匹配,则结果为 NULL。 SQL LEFT JOIN 语法 SELECT column_name(s) FROM...

    MySQL表LEFT JOIN左连接与RIGHT JOIN右连接的实例教程

    FROM table1 LEFT JOIN table2 ON condition ... MySQL LEFT JOIN 用法实例 下面是两个原始数据表: article 文章表: user 用户表: 我们列出所有的文章及对应的所属用户,即使没有用户的文章也列出。 SELECT ...

    SQLQuery5.sql

    from score a left join ( select a.s_score from Score a group by a.s_score having count(a.s_score)>1 and count(distinct a.c_id) > 1)tt on tt.s_score=a.s_score group by a.s_id select distinct a.s_...

    U8-MRP供需平衡分析脚本(非专业人士误入)

    通过SQL存储过程及视图来部署基于U8-ERP系统的自定义报表,功能强大,弥补了U8系统的供需分析的缺陷,...'+'FROM TEMP_BOM_COMP A LEFT JOIN '+@cTableName + ' B ON A.子件编码 =B.CINVCODE';非专业人士请不要下载!

    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 说明:日程安排提前五分钟提醒 select * from 日程安排 where datediff('minute',f开始时间,getdate())>5 说明:两张关联表,删除主表...

    优化sql的测试数据

    LEFT JOIN WareHouseAreaInfo b ON b.WIID = a.WIID GROUP BY a.ProductID ) psi ON psi.ProductID = PI.ID left JOIN (SELECT ProductID,PicName FROM ProductPic where Sort = 1) as PP ON PI.ID = PP.ProductID ...

    数据库Left join , Right Join, Inner Join 的相关内容,非常实用

    一.先看一些最简单的例子 例子 Table Aaid adate 1 a1 2 a2 3 a3 ...那么left join 指: select * from a left join b on a.aid = b.bid 首先取出a表中所有数据,然后再加上与a,b匹配的的数据 此时的

    mysql使用GROUP BY分组实现取前N条记录的方法

    本文实例讲述了mysql使用GROUP BY分组实现取前N条记录的方法。分享给大家供大家参考,... 代码如下:SELECT a.id,a.SName,a.ClsNo,a.Score FROM aa a LEFT JOIN aa b ON a.ClsNo=b.ClsNo AND a.Score<b.Score group

    SSD7 选择题。Multiple-Choice

    When mapping from an ER model to a relational model, a strong entity is mapped into a (a) table (b) row (c) column (d) key Correct answer is (a) 10. Which of the following is true about ...

Global site tag (gtag.js) - Google Analytics