Gossamer Forum
Home : Products : Gossamer Links : Development, Plugins and Globals :

selecting from 2 tables - left joins?

Quote Reply
selecting from 2 tables - left joins?
Hello!

Here's what I'm trying to do... I've got 2 tables in my database - A & B.

A has multiple columns, one of which = gid.
B has 2 columns = pid_fk, gid_fk.

The gid_fk column in B is a foreign key that relates to the gid column in table A.

What I want to do is select all the records in table A that DON'T have a corresponding record in table B. ie. select all those from A whos gid "does not" appear in B as a gid_fk.

Then I also need code that does the opposite - select all records from A whos gid "does" appear in B as a gid_fk.

I believe it's done with a left join statement but I can't figure out how to use it.

Can anyone help?

Thanks!
Quote Reply
Re: [ryel01] selecting from 2 tables - left joins? In reply to
Maybe something like this:

SELECT gid FROM A LEFT JOIN B ON A.gid = B.gid_fk WHERE gid_fk IS NULL