sql相關問題
阿新 • • 發佈:2021-01-22
文章目錄
一. mysql查詢相關問題
1.1 left join表
眾所周知,left join表的時候小表驅動大表,左邊的表全量顯示,但是如何不全量顯示呢?
- 全量顯示左表:
--根據userId檢視使用者角色
select * from sys_role role
LEFT JOIN sys_user_role user_role on role.role_id=user_role.role_id and user_role.user_id=100
where role.del_flag= '0' ;
2. 上邊的查詢是有問題的,所以怎麼顯示一條想要的資料呢?
on後邊只過濾id,不過濾真正的user條件,放到where後邊
--根據userId檢視使用者角色
select * from sys_role role
LEFT JOIN sys_user_role user_role on role.role_id=user_role.role_id
where role.del_flag='0' and user_role.user_id=100;