select a.*,c.device_name from device_warn as a
inner join user_warn as b
on a.id=b.warn_id and b.state=1 inner join
device_info as c
on c.DEVICE_ID=a.DEVICE_ID
where a.DEVICE_ID in (select DEVICE_ID from device_station where STATION_ID in (select STATION_ID from station_user where USER_ID=4))
本条sql语句涉及到了三个表的联查,分别是device_warn,user_warn,device_info,
其中,device_warn,user_warn,device_info的表结构分别如下:
![](https://img-blog.csdnimg.cn/20210113135049898.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3Vlc3RjbHI=,size_16,color_FFFFFF,t_70)
易错问题,where条件必须在join条件之后。