2017-03-02 85 views
0

我有2個表MYSQL不存在工作不

courseobjects表

id_objects | type  | id_type | completed | id_courses 
41   |movie  |25  |0   |27 
42   |presentation|11  |0   |27 
43   |movie  |26  |0   |27 

courseobjectsresults

id_courseresult | id_courseobject |id_user |result 
92    |41    |62  |1  

我想表明courseobjects表中的行,其中ID是不存在的 courseobjectsresults(id_courseobject)

我想:

SELECT * FROM courseobjects WHERE NOT EXISTS (SELECT * FROM courseobjectsresults WHERE courseobjectsresults.id_courseobject <> '41') 

輸出我得到的是空,但它應該從courseobject顯示一行ID 42和43個

感謝。不存在

SELECT * 
FROM courseobjects 
WHERE NOT EXISTS (
    SELECT 1 
    FROM courseobjectsresults 
    HERE courseobjectsresults.id_courseobject = courseobjects.id_objects 
) 

回答

1

您的查詢是有點邏輯錯誤,而你還只是測試對ID 41.試試這個

可以使用(where column IN)和(where column NOT IN

+0

謝謝!有用! – Phoenix

0

替補: