Unix Technical Forum

Help with negative join syntax?

This is a discussion on Help with negative join syntax? within the MySQL forums, part of the Database Server Software category; --> Hi, Not sure if query syntax is germane here. If not please advise as to a group where I ...


Go Back   Unix Technical Forum > Database Server Software > MySQL

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-28-2008, 11:30 AM
jerrygarciuh
 
Posts: n/a
Default Help with negative join syntax?

Hi,

Not sure if query syntax is germane here. If not please advise as to
a group where I could ask.

I need to do a kind of join that I have not had to do before. I need
to find records which exist only in one of two tables.

Everyone has a record in `person` but not every person record has an
attendant `contest_entry` record. I need to find records that exist
in `person` but not in `contest_entry`.

So I tried

SELECT person.id, contest_entry.person
FROM person, contest_entry
WHERE person.datetime_added > '2007-11-27'
AND person.id != contest_entry.person

which got me 81,174,327 results as a factorial of the two sets. Who
do I make this negative join?

TIA!!

jg
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-28-2008, 11:30 AM
Paul Lautman
 
Posts: n/a
Default Re: Help with negative join syntax?

jerrygarciuh wrote:
> Hi,
>
> Not sure if query syntax is germane here. If not please advise as to
> a group where I could ask.
>
> I need to do a kind of join that I have not had to do before. I need
> to find records which exist only in one of two tables.
>
> Everyone has a record in `person` but not every person record has an
> attendant `contest_entry` record. I need to find records that exist
> in `person` but not in `contest_entry`.
>
> So I tried
>
> SELECT person.id, contest_entry.person
> FROM person, contest_entry
> WHERE person.datetime_added > '2007-11-27'
> AND person.id != contest_entry.person
>
> which got me 81,174,327 results as a factorial of the two sets. Who
> do I make this negative join?
>
> TIA!!
>
> jg


SELECT
person.id,
contest_entry.person
FROM person
LEFT JOIN contest_entry ON person.id = contest_entry.person
WHERE person.datetime_added > '2007-11-27'
AND contest_entry.person IS NULL


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-28-2008, 11:30 AM
knotinmybackyard@gmail.com
 
Posts: n/a
Default Re: Help with negative join syntax?

Thank you!!! The next time you are in New Orleans I owe you a beer!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 06:07 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
www.UnixAdminTalk.com