我想根据两个关系表从表中选择用户
结构:
[user]
uid | firstname | lastname | ...
---------------------------------
482 | USERa | USERa | ...
885 | USERb | USERb | ...
405 | USERc | USERc | ...
385 | USERd | USERd | ...
[news_info]
uid_local | uid_foreign
--------------------------------
125 | 482
100 | 405
[news_add]
uid_local | uid_foreign
--------------------------------
125 | 885
105 | 385
现在我只想通过 uid_local -> 125 选择 USERa 和 USERb,来自 [news_info] 和 [news_add]
SELECT
nnfo.uid_local,
user.*
FROM user
JOIN news_info nnfo
ON nnfo.uid_foreign = user.uid
WHERE nnfo.uid_local = 125
结果 = USERa // 有效
SELECT
nadd.uid_local,
user.*
FROM user
JOIN news_add nadd
ON nadd.uid_foreign = user.uid
WHERE nadd.uid_local = 125
结果 = USERb // 有效
现在将 sql 语句“合并”为一个...以获取 USERa 和 USERb
SELECT
nnfo.uid_local,
nadd.uid_local,
user.*
FROM user
JOIN news_info nnfo
ON nnfo.uid_foreign = user.uid
JOIN news_add nadd
ON nadd.uid_foreign = user.uid
WHERE nnfo.uid_local = 125 AND nadd.uid_local = 125
结果 = 空 // 没有错误.....
出了什么问题...我尝试了其他一些陈述,但没有结果:(