SQL中exists关键字的用法
SQL中exits关键字的用法
1.简单的写一个sql,查询user表中和role_user表中互相关联的数据:
select * from user u where u.id in (select ru.user_id from role_user ru);
这样就可以查询出两张表互相关联的数据。
2.使用exits关键字进行优化。
select * from user u where exits (select 1 from role_user ru where u.id = ru.id );
3.同理
原创
2021-10-13 15:55:53 ·
97 阅读 ·
0 评论