Jump to content


Photo

Selecting ID's not listed in Joined table


  • Please log in to reply
1 reply to this topic

#1 thorak

thorak
  • New Members
  • Pip
  • Newbie
  • 1 posts

Posted 07 August 2003 - 08:25 PM

ok... so here is what i have... and its driving me crazy.

I have 2 tables.... tblmessage and tblwhoview.

tblmessage = all the message
tblwhoview = who is allowed to view the messages

I need to write a query that will select all the message from tblmessage that are not in the tblwhoview.... so i tried these, but nothing is working.

SELECT DISTINCT M.ID FROM tblmessages M, tblwhoview W WHERE M.ID != W.MID

SELECT DISTINCT M.ID FROM tblmessages M LEFT JOIN tblwhoview W ON M.ID=W.MID WHERE M.ID != W.MID

can someone please help me.... im going crazy.

thanks
ryan

#2 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,020 posts

Posted 08 August 2003 - 05:24 PM

You were getting close with that second attempt.

SELECT DISTINCT M.ID FROM tblmessages M LEFT JOIN tblwhoview W ON M.ID=W.MID WHERE W.ID IS NULL
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users