db-torque-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Thomas Vandahl ...@apache.org>
Subject Re: Left Join on multiple clauses
Date Mon, 22 Oct 2007 17:20:32 GMT
Jonathan Halland wrote:
> If I move the CAMPAIGN_ID=16 to the where clause I will essentially have the
> same as a inner join, I however need to access the records that do not
> necessarily have a matching record in the right side table.

If I understand you correctly, you are trying to get all records from
table "account" which may or may not have a matching record in table
"campaign_handled_objects", right?

> 	LEFT JOIN campaign_handled_objects on
> accounts.ACCOUNT_ID=campaign_handled_objects.OBJECT_ID AND
> campaign_handled_objects.CAMPAIGN_ID=16

What you do here is to query all records from table "account" which *do*
have a matching record in table "campaign_handled_objects", namely the
ones that have CAMPAIGN_ID=16. This is in fact an inner join, because
you specified a record field from the right table to be *not null*,
which means that the record must exist. The correct SQL for the above
would read like

	LEFT JOIN campaign_handled_objects on
accounts.ACCOUNT_ID=campaign_handled_objects.OBJECT_ID
WHERE (campaign_handled_objects.CAMPAIGN_ID=16 OR
campaign_handled_objects.CAMPAIGN_ID=16 IS NULL)

Bye, Thomas.


---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org


Mime
View raw message