Jump to content


Photo

Select from one table if index doesn't exist in another table?


  • Please log in to reply
2 replies to this topic

#1 m11oct

m11oct
  • New Members
  • Pip
  • Newbie
  • 7 posts

Posted 13 September 2006 - 09:14 AM

If you don't know about MySQL syntax then please just ignore this post...

I'm having a MySQL Query problem as I don't know how to write it...

I want to select columns B and C from TABLE2 if the value from C in TABLE1 doesn't exist as a column A in TABLE1 at all.

Column A is the index for TABLE1 and column B is the index for TABLE2 while column C in TABLE2 refers to a row from TABLE1.

However, it appears there are quite a lot of cases in TABLE2 where the row column C referes to in TABLE1 no longer exists and I'd like to be able to select all of these.

Any ideas?

#2 shoz

shoz
  • Staff Alumni
  • Advanced Member
  • 600 posts

Posted 13 September 2006 - 10:53 AM

if the value from C in TABLE1 doesn't exist as a column A in TABLE1 at all.

Did you mean C in TABLE2?

SELECT
table2.B, table2.C
FROM
table2
LEFT JOIN 
table1
ON
table2.C = table1.A
WHERE
table1.A IS NULL
http://dev.mysql.com....1/en/join.html

#3 m11oct

m11oct
  • New Members
  • Pip
  • Newbie
  • 7 posts

Posted 14 September 2006 - 07:53 PM

That works well, thank you very much.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users