Akshay Naik Akshay Naik - 1 month ago 8
MySQL Question

How to search everything except something

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

Answer

How about this?

SQLFIDDLE DEMO

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

Results:

| ID |   TITLE |
----------------
|  1 | country |
Comments