一个嵌套查询sql语句(mysql)
SELECTTerminalName,CapabilityFROMt_terminalWHEREVehicleIDIN(SELECTVehicleIDFROMt_vehi...
SELECT TerminalName, Capability FROM t_terminal WHERE VehicleID IN (SELECT VehicleID FROM t_vehicleorgan WHERE OrganID IN (SELECT OrganID FROM t_userorgan WHERE UserID = ?))
----------
我想,把OrganID也查出来怎么写啊 展开
----------
我想,把OrganID也查出来怎么写啊 展开
展开全部
select a.TerminalName, a.Capability,c.OrganID
from t_terminal a,t_vehicleorgan b,t_userorgan c
where a.VehicleID=b.VehicleID and b.OrganID =c.OrganID and c.UserID = ?
这样试试,最后的userid=?那自己输入一个值
追问
不是一对一的关系,SELECT OrganID FROM t_userorgan WHERE UserID = ? ->这个执行后会出现很多OrganID
SELECT VehicleID FROM t_vehicleorgan WHERE OrganID IN 上面的OrganID ->这个执行后会出现很多VehicleID
追答
select a.TerminalName, a.Capability,b.OrganID
from t_terminal a,t_vehicleorgan b
where exists
(selec 1 from t_userorgan c where b.OrganID =c.OrganID and c.UserID = ?)
展开全部
SELECT a.TerminalName, a.Capability , b.OrganID
FROM t_terminal a
JOIN t_vehicleorgan b on a.VehicleID = b.VehicleID
WHERE 1=1
AND EXISTS (SELECT 1
FROM t_userorgan c
WHERE 1=1
AND c.OrganID=b.OrganID
AND UserID = ?
)
追问
可以运行
不是一对一的关系,SELECT OrganID FROM t_userorgan WHERE UserID = ? ->这个执行后会出现很多OrganID
SELECT VehicleID FROM t_vehicleorgan WHERE OrganID IN 上面的OrganID ->这个执行后会出现很多VehicleID
追答
那么出现多行不同的OrganID时你想怎么办?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询