mysql 语句收藏(备查)


1、inner join同时查3个表


人员表employee(字段:name,dept_idpost_id);
部门表dept(字段:dept_id,dept_name);
岗位表position(字段:post_id,post_name)。

SELECT employee.name,dept.dept_name,position.post_name from employee 
inner join dept on employee.dept_id=dept.dept_id 
inner join position on employee.post_id=position.post_id;
这样就可以一步查出姓名、部门名称、岗位名称了。

2、4种不同的JOINs:

INNER JOIN: Return rows when there is at least one match in both tables,只检索出两边都得有数据的行,下面的类推
LEFT JOIN: Return all rows from the left table, even if there are no matches in the right table,右边没有没关系
RIGHT JOIN: Return all rows from the right table, even if there are no matches in the left table,左边没有没关系
FULL JOIN: Return rows when there is a match in one of the tables,任何一边有就行
语法基本一样,例句:

SELECT column_name(s)
FROM table_name1
INNER JOIN table_name2
ON table_name1.column_name=table_name2.column_name

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值