我有表:
User Table
User_id| Preferences |Blood_Group|City
Events Table
Event_id|Event_type|Blood_Group|Event_city|Event_Addded_By|Description
Commit Table
User_id|Event_id
我将发送 user_id,以便我希望查询返回那些事件,这些事件是用户和 blood_group 中首选的事件,事件表中的城市与用户表中的值相同,并且该事件尚未提交提交表中的用户。
提前致谢。
最佳答案
这可能对您有帮助:
SELECT [Required Columns]
FROM [User Table] UT JOIN [Event Table] ET
ON ET.Bloodgroup = UT.Bloodgroup
AND ET.City = UT.City
WHERE NOT EXISTS (
SELECT 1 FROM [Commit Table] CT
WHERE CT.UserId = UT.UserId
AND ET.EventId = CT.EventId
)
AND UT.UserId = @UserId
关于mysql - 3 个表的 SQL 查询或连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31803253/