Association Table Query

Login or register to post comments
2 replies [Last post]
Offline
Joined: 12/06/2010

Hi QCubed Gurus,

I have an assciation table LR_CHALLAN_ASSN which has keys from tables LR and CHALLAN.

I need to figure out how to get the unassociated LRs which are not mapped to any challan. Any help on this guys..

Offline
Joined: 12/06/2010

After an 8 hour research I found that Mysql does not support MINUS statement
duh...
Here's the alernative which can save time..

SELECT DISTINCT lr.id
FROM lr
WHERE (lr.id) NOT IN
(SELECT lr_id FROM lr_challan_assn);

Offline
Joined: 04/22/2009

Hello,

In MySQL you use a LEFT JOIN for this like in here:

SELECT *
FROM person
LEFT JOIN team_member_project_assn
ON team_member_project_assn.person_id=person.id
WHERE person_id IS NULL

Might be better performance wise as MySQL is not that great with sub-selects.

Cheers

Helge