Jump to content

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


m11oct

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?
Link to comment
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
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.