复杂的sql语句join的使用(left join,right join)_MySQL
程序员文章站
2022-05-19 14:36:56
...
bitsCN.com
SELECT u.*,count(u.id) AS sum
02
FROM user AS u
03
LEFT JOIN post AS p
04
ON p.user_id = u.id
05
RIGHT JOIN user_has_group as up
06
ON up.user_id = u.id
07
RIGHT JOIN user_has_email as ue
08
ON ue.user_id = u.id
09
WHERE u.username != ''
10
AND up.group_id = {$args['groupid']}
11
AND ue.email = '{$args['useremail']}'
12
GROUP BY u.id ORDER BY u.id desc bitsCN.com
02
FROM user AS u
03
LEFT JOIN post AS p
04
ON p.user_id = u.id
05
RIGHT JOIN user_has_group as up
06
ON up.user_id = u.id
07
RIGHT JOIN user_has_email as ue
08
ON ue.user_id = u.id
09
WHERE u.username != ''
10
AND up.group_id = {$args['groupid']}
11
AND ue.email = '{$args['useremail']}'
12
GROUP BY u.id ORDER BY u.id desc bitsCN.com
上一篇: ElTableColumn扩展方法详解
推荐阅读
-
数据库Left join , Right Join, Inner Join 的相关内容,非常实用
-
解析mysql left( right ) join使用on与where筛选的差异
-
MySQL中(JOIN/ORDER BY)语句的查询过程及优化方法
-
SQL中的left join right join
-
sql中的left join以及on、where关键字的区别
-
oracle中left join和right join的区别浅谈
-
SQL语句的并集UNION 交集JOIN(内连接,外连接)等介绍
-
SQL语句中不同的连接JOIN及join的用法
-
Mysql中Join的使用实例详解
-
神奇的 SQL 之 联表细节 → MySQL JOIN 的执行过程(二)