知道为什么我无法使用 ID 过滤此查询吗? 我需要值为 NULL 的查询(如果不可用)。 这不起作用:
SELECT lektions_themen.titel, lektions_themen.id,
lektions_themen.subtitel,lektions_themen.bild,
user_lektion.email
FROM `user_lektion`
INNER JOIN lektions_themen
ON
user_lektion.kurs_id=lektions_themen.kurs_id
WHERE user_lektion.id=$id
这是一个示例:
LECTIONS
#id #title#
1 Mathe
2 Latin
3 English
4 Greek
USER
#UserLectionID #Name #UserId #lectionId
2 Fritz 1 2
3 Fritz 1 3
4 Paul 2 1
5 Paul 2 2
RESULT (userID=1)
#Name #title
Fritz NULL
Fritz Latin
Fritz English
Fritz NULL
我需要 UserId=1 的所有类(class)
最佳答案
好的,明白了
SELECT lektions_themen.titel, lektions_themen.id,
lektions_themen.subtitel,lektions_themen.bild,
user_lektion.email
FROM `user_lektion`
INNER JOIN lektions_themen
ON
user_lektion.kurs_id=lektions_themen.kurs_id
AND user_lektion.email='$id'
关于MYSQL LEFT JOIN - 按用户过滤,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24247939/