Forum Moderators: open

Message Too Old, No Replies

MySQL 3 Join condition problem

need to isolate records that have no record in 2nd table

         

warth0g

6:10 pm on Aug 25, 2009 (gmt 0)

10+ Year Member



I am trying to get a list of records that are missing a record in a second table. (or have only a record with a specific condition in that second table)

so i have a main table that has notes attached to it

I want to query the table, join on the notes table and just get a list of records that have zero notes or only have notes with a staff_id of 0 (eg system notes)

If I do a regulat join i get all the records that have notes with only system notes but it omits the records with zero notes

like so:

SELECT r.rfq_id FROM `rfq` r
inner JOIN rfq_admin_notes n on r.rfq_id = n.rfq_id
where n.staff_id <= 0
group by n.rfq_id

- this gives me a list of all rfqs that only have system notes, but i also need the ones that have zero notes, so i tried an old join like so:

SELECT r.rfq_id FROM `rfq` r, rfq_admin_notes n
where n.staff_id = 0
group by r.rfq_id

- this gives me all the records even ones with notes that have staff_ids above 0, I tried :

SELECT r.rfq_id FROM `rfq` r, rfq_admin_notes n
where (n.staff_id = 0 OR n.staff_id = '')
group by r.rfq_id

but it gives the same results - is there a way to do this so i can just get the records that have a note with a staff_id of 0 OR no note in the second table?

this is mysql3 so i cant do really fancy joins and selects

warth0g

6:31 pm on Aug 25, 2009 (gmt 0)

10+ Year Member



well i decided to just do a query of a query so that fixed it - nevermind