我在数据库中有3个表。
第一个表格(news
)“所有新闻发布”,列
NEWS_ID
第二个表(plyrs_read
)“阅读新闻的玩家和哪些新闻”栏目
PLAYER_ID | NEWS_ID
第3个表格(players
),其中包含“服务器上的所有玩家”。列
PLAYER_ID
我想向玩家展示玩家没有读过的所有新闻。我的身份证明是$ id。
现在我需要帮助才能将所有NEWS_ID
放入数组
答案 0 :(得分:2)
这个怎么样?
select * from news n
where id not in(select pn.nid
from player_news pn
where pn.pid = 1)
;
结果:
| ID | TITLE |
----------------
| 1 | country |
答案 1 :(得分:1)
SELECT *
FROM news
WHERE news_id NOT IN(SELECT r.news_ID
FROM plyrs_read r
INNER JOIN players p ON r.Player_ID = p.Player_ID
WHERE p.player_ID = 'some id'
AND r.news_ID IS NOT NULL);
答案 2 :(得分:0)
SELECT NEWS_ID FROM table1
WHERE NEWS_ID NOT IN
( SELECT NEWS_ID FROM table2 WHERE PLAYER_ID = $id )
答案 3 :(得分:0)
SELECT n.NEWS_ID FROM news n
LEFT OUTER JOIN plyrs_read pr
ON n.NEWS_ID = pr.NEWS_ID AND pr.PLAYER_ID = $id
WHERE pr.NEWS_ID IS NULL