Link to home
Start Free TrialLog in
Avatar of asrisbey
asrisbey

asked on

SQL Multiple JOINS to same table

I've got this query:

SELECT  View_CMS_Tree_Joined.*, CONTENT_Event.*, act1.*, act2.*
FROM View_CMS_Tree_Joined  
INNER JOIN CONTENT_Event
ON View_CMS_Tree_Joined.DocumentForeignKeyValue = CONTENT_Event.[eventID]
LEFT JOIN custom_activity AS act1
ON CONTENT_Event.[EventActivity] = act1.[activityID]
LEFT JOIN custom_activity AS act2
ON CONTENT_Event.[EventActivity2] = act2.[activityID]

It is returning the correct data - but the field names returned for act1 and act2 are identical - which makes it impossible to distinguish between act1.field1 and act2.field1. I'm obviously doing something wrong here.

Thanks for any help.
ASKER CERTIFIED SOLUTION
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of asrisbey
asrisbey

ASKER

Another great solution from angellll - thanks, works a treat.