小编jac*_*him的帖子

查询多个EXIST

我有一个房间和设备的数据库.我想查询数据库并返回一个房间列表,例如电视,收音机,卫星和冰箱(eq1,eq2,eq3,....,eqN).

我有以下SELECT语句:

select * from rooms r where 
exists (select id from equipments where eq_id='eq1' and room_id=r.id)
and
exists (select id from equipments where eq_id='eq2' and room_id=r.id)
and
exists (select id from equipments where eq_id='eq3' and room_id=r.id)
.......
and
exists (select id from equipments where eq_id='eqN' and room_id=r.id)
Run Code Online (Sandbox Code Playgroud)

有没有什么方法可以优化或缩短它?

mysql exists

5
推荐指数
1
解决办法
2440
查看次数

标签 统计

exists ×1

mysql ×1