If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Help with a Join query with null rows

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-08-11, 00:03
RGM RGM is offline
Registered User
 
Join Date: Feb 2011
Posts: 29
Help with a Join query with null rows

I'm trying to get records from the left table where they don't have a corrosponding record in the right table.

The scenario is:
events expire and when they do, a notification should be set, but only once.

So, I'm trying to find events with a type_id of 2 that have expired from the left table and join to the right table to find if they already have a message of type 3.

If they don't, I want the event row. If they do, I don't want anything.

My query so far:

Code:
SELECT c.id
FROM SA_causes c
LEFT OUTER
JOIN SA_feeds_causes fc
on fc.cause_id = c.id
WHERE c.type_id = 2 
AND fc.id is null 
AND c.end_date >= "2011-07-08 15:56:24" 
AND fc.type_id = 3

Thanks for any help
Reply With Quote
  #2 (permalink)  
Old 07-08-11, 02:14
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
Code:
SELECT c.id
  FROM SA_causes c
LEFT OUTER
  JOIN SA_feeds_causes fc
    ON fc.cause_id = c.id
   AND fc.type_id = 3
 WHERE c.type_id = 2 
   AND c.end_date >= '2011-07-08 15:56:24' 
   AND fc.id IS NULL
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 07-08-11, 02:37
RGM RGM is offline
Registered User
 
Join Date: Feb 2011
Posts: 29
Uh, can't believe that cost me hours.

Thank you Rudy.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On