1

I have 3 tables in the database.

1st table (news) of "All news released" with columns

NEWS_ID

2nd table (plyrs_read) of "players who read the news and which news" with columns

PLAYER_ID | NEWS_ID

3rd table (players) with of "All players on server". with columns

PLAYER_ID

I want to show a player all the news which the player hasn`t read. I have his id in $id.

Now I need help to get all those NEWS_ID in an array

4

4 回答 4

2

这个怎么样?

SQLFIDDLE 演示

select * from news n
where id not in(select pn.nid 
                from player_news pn
                where pn.pid = 1)
;

结果:

| ID |   TITLE |
----------------
|  1 | country |
于 2013-01-21T07:52:18.657 回答
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);

SQL 小提琴演示

于 2013-01-21T07:23:14.490 回答
0
SELECT NEWS_ID FROM table1
WHERE NEWS_ID NOT IN
    ( SELECT NEWS_ID FROM table2 WHERE PLAYER_ID = $id )
于 2013-01-21T07:23:26.247 回答
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
于 2013-01-21T07:24:58.380 回答