right join 的正确用法

今夜把成都想起2022-10-04 11:39:541条回答

已提交,审核后显示!提交回复

共1条回复
glszmm 共回答了21个问题 | 采纳率85.7%
ight join
编辑本段
right join:
是SQL语言中的查询类型,即连接查询.它的全称为右外连接( right outer join),是外连接的一种.
用法:
连接通常可以在select语句的from子句或where子句中建立,其语法格式为:
from join_table join_type join_table
[on (join_condition)]
其中join_table指出参与连接操作的表名,连接可以对同一个表操作,也可以对多表操作.对同一个表操作的连接称为自连接.
on (join_condition)用来指连接条件,它由被连接表中的列和比较运算符、逻辑运算符等构成.
举例说明:
例1:select bookinfo.bookname ,authorinfo.hometown
from bookinfo right join authorinfo
on bookinfo.authorname=authorinfo.authorname;
例2:表A记录如下:
aID aNum
1 a20050111
2 a20050112
3 a20050113
4 a20050114
5 a20050115
表B记录如下:
bID bName
1 2006032401
2 2006032402
3 2006032403
4 2006032404
8 2006032408
SQL语句:select * from A right join B on A.aID = B.bID;
结果如下:
aID aNum bID bName
1 a20050111 1 2006032401
2 a20050112 2 2006032402
3 a20050113 3 2006032403
4 a20050114 4 2006032404
NULL NULL 8 2006032408
(所影响的行数为 5 行)
结果说明:
right join是以B表的记录为基础的,A可以看成左表,B可以看成右表,right join是以右表为准的.换句话说,右表(B)的记录将会全部表示出来,而左表(A)只会显示符合搜索条件的记录(例子中为:A.aID = B.bID).A表记录不足的地方均为NULL.
1年前

相关推荐

SSH怎么使用外连接.right join,left join
SSH怎么使用外连接.right join,left join

Caused by:org.hibernate.hql.ast.QuerySyntaxException:Path expected for join![from com.eskytech.budget.dept.vo.BDeptLeaderMappingImpl a right join SysOrgVOImpl b where a.deptCode=orgId and a.compCode='01' ]
挣扎19771年前1
小鬼不再 共回答了18个问题 | 采纳率77.8%
把where 改成on就行 因为join on是一个语句 意思是根据on后的条件 外连接
BDeptLeaderMappingImpl a right join SysOrgVOImpl b [on] a.deptCode=orgId
望采纳

大家在问