I need to know how to do a SQL query in Access that does an outer join with another table...but here's the problem:
The joined table needs to be qualified by date...i.e. I want the results set to show ALL records qualified in the main select statement (all locations by City found in 'British Columbia') BUT I only want to join with those records in the Events table that have an eventDate > today.
How do I do that?
SELECT DISTINCTROW Locations.City, Locations.StateProv, Locations.Contact, Locations.Phone1, Events.eventLocID, Events.EventName, Events.EventDate, Events.EventDetails
FROM Locations LEFT JOIN Events ON Locations.ID = Events.eventLocID
WHERE Locations.StateProv = 'British Columbia'
GROUP BY Locations.StateProv, Locations.City, Locations.Contact, Locations.Phone1, Events.EventLocID, Events.EventName, Events.EventDate, Events.EventDetails ORDER BY City, EventDate
I am used to Oracle SQL where you can use the IN operator (?) such as WHERE id IN ( SELECT eventLocID FROM events WHERE eventDate > #11/11/02#)
But when I tried that below, it gives an syntax error so I assume Access doesn't understand IN.
SELECT DISTINCTROW Locations.City, Locations.StateProv, Locations.Contact, Locations.Phone1, Events.eventLocID, Events.EventName, Events.EventDate, Events.EventDetails FROM Locations LEFT JOIN Events ON Locations.ID IN ( SELECT EventLocID FROM Events WHERE EventDate > #11/11/02# ) WHERE Locations.StateProv = 'British Columbia' GROUP BY Locations.StateProv, Locations.City, Locations.Contact, Locations.Phone1, Events.EventLocID, Events.EventName, Events.EventDate, Events.EventDetails ORDER BY City, EventDate
The joined table needs to be qualified by date...i.e. I want the results set to show ALL records qualified in the main select statement (all locations by City found in 'British Columbia') BUT I only want to join with those records in the Events table that have an eventDate > today.
How do I do that?
SELECT DISTINCTROW Locations.City, Locations.StateProv, Locations.Contact, Locations.Phone1, Events.eventLocID, Events.EventName, Events.EventDate, Events.EventDetails
FROM Locations LEFT JOIN Events ON Locations.ID = Events.eventLocID
WHERE Locations.StateProv = 'British Columbia'
GROUP BY Locations.StateProv, Locations.City, Locations.Contact, Locations.Phone1, Events.EventLocID, Events.EventName, Events.EventDate, Events.EventDetails ORDER BY City, EventDate
I am used to Oracle SQL where you can use the IN operator (?) such as WHERE id IN ( SELECT eventLocID FROM events WHERE eventDate > #11/11/02#)
But when I tried that below, it gives an syntax error so I assume Access doesn't understand IN.
SELECT DISTINCTROW Locations.City, Locations.StateProv, Locations.Contact, Locations.Phone1, Events.eventLocID, Events.EventName, Events.EventDate, Events.EventDetails FROM Locations LEFT JOIN Events ON Locations.ID IN ( SELECT EventLocID FROM Events WHERE EventDate > #11/11/02# ) WHERE Locations.StateProv = 'British Columbia' GROUP BY Locations.StateProv, Locations.City, Locations.Contact, Locations.Phone1, Events.EventLocID, Events.EventName, Events.EventDate, Events.EventDetails ORDER BY City, EventDate