Jump to content

Archived

This topic is now archived and is closed to further replies.

m11oct

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

Recommended Posts

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?

Share this post


Link to post
Share on other sites
[quote=m11oct]
if the value from C in TABLE1 doesn't exist as a column A in TABLE1 at all.
[/quote]
Did you mean C in TABLE2?

[code]
SELECT
table2.B, table2.C
FROM
table2
LEFT JOIN
table1
ON
table2.C = table1.A
WHERE
table1.A IS NULL
[/code]
http://dev.mysql.com/doc/refman/4.1/en/join.html

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.