有这张桌子
Table "Items" itemID itemTitle itemContent
还有这个
Table "MyList" userID itemID deleted
如果给定用户ID,即使"MyList"中不存在itemID,如何从表"Items"中选择所有行并显示"已删除"字段?
查询结果示例:
itemID | itemTitle | deleted | userID ------------------------------------- 1 | Title1 | 1 | 2 2 | Title2 | 0 | 2 3 | Title3 | (null) | (null) 4 | Title4 | (null) | (null)
什么是查询,以便我可以得到那个结果?
谢谢
SELECT I.itemID, I.itemTitle, M.deleted FROM Items I LEFT OUTER JOIN MyList M ON M.itemID = I.itemID WHERE M.userID = 9
编辑:基于OP的评论:
SELECT I.itemID, I.itemTitle, M.deleted, M.userID FROM MyList M LEFT OUTER JOIN Items I ON I.itemID = M.itemID WHERE M.userID = 9