如何根据条件设置联接,我尝试使用if或case来执行此操作,如何实现此目的。 mysql错误代码:1241。操作数应包含1列
SET @sUserId = 15;
SELECT userClip.userId
FROM
( select if(@sUserId > 0 ,(select * from groups),(select * from otherGroups))folderId)abc
INNER JOIN userClip
on abc.folderId = userClip.folderId
最佳答案
您可以将条件分为两个左联接。这应该起作用,因为您的@sUserId不能同时为>和我也将userClip
更改为userFolder
,因为您好像把它们混在一起了(如果没有,请提供反馈)。
两个LEFT_JOINS:
SELECT userFolder.userId
FROM
userFolder
LEFT JOIN (SELECT * FROM groups) as abc
on(@sUserId>0 and abc.folderId = userFolder.folderId)
LEFT JOIN (SELECT * FROM otherGroups) as bcd
on(@sUserId>=0 and bcd.folderId = userFolder.folderId)