Darren Bartrup
Well-known Member
- Joined
- Mar 13, 2006
- Messages
- 1,296
- Office Version
- 365
- Platform
- Windows
EDIT: The heading should just read 'Which UNION query runs faster'
Hi all,
I need to use a subquery to exclude records from the main query. Which way of writing it would be better?
This way unions it all together before checking the ListDate and I need to use DISTINCT to exclude duplicates as the ListDate changes on each record:
Or this way, which has to look the calendar form three times:
I'm thinking it's probably the first query as there's less calls to the form?
Hi all,
I need to use a subquery to exclude records from the main query. Which way of writing it would be better?
This way unions it all together before checking the ListDate and I need to use DISTINCT to exclude duplicates as the ListDate changes on each record:
Code:
SELECT DISTINCT User
FROM (
SELECT User,
ListDate
FROM Contact_List_CL
UNION SELECT User,
ListDate
FROM Contact_List_IN
UNION SELECT User,
ListDate
FROM Contact_List_OL
)
WHERE ListDate BETWEEN [Forms].[frmCalendar].[clndr]-1
AND [Forms].[frmCalendar].[clndr]-6
Or this way, which has to look the calendar form three times:
Code:
SELECT User,
FROM Contact_List_CL
WHERE ListDate BETWEEN [Forms].[frmCalendar].[clndr]-1
AND [Forms].[frmCalendar].[clndr]-6
UNION SELECT User,
FROM Contact_List_IN
WHERE ListDate BETWEEN [Forms].[frmCalendar].[clndr]-1
AND [Forms].[frmCalendar].[clndr]-6
UNION SELECT User,
FROM Contact_List_OL
WHERE ListDate BETWEEN [Forms].[frmCalendar].[clndr]-1
AND [Forms].[frmCalendar].[clndr]-6
I'm thinking it's probably the first query as there's less calls to the form?