bretedward
New member
- Local time
- Today, 18:41
- Joined
- Aug 10, 2014
- Messages
- 5
[FONT="]I have SQL query/dual sub-query in MS Access that is returning data from the left side of the query FROM correctly, but is only returning one record from the right side of the query FROM. Furthermore, it repeats the display of the one record and it repeats the entire results set with a different one record each time until all the records have been displayed. I expect that problems described as “Furthermore” will not exist by fixing the one record issue. I have tried using all the join types available in MS Access, but none change the result.
[/FONT]
[FONT="]
[/FONT]
[FONT="]The desired output is:[/FONT]
[FONT="]Yellow[/FONT][FONT="] Blue[/FONT]
[FONT="]11/23/2013 11/19/2013[/FONT]
[FONT="]11/19/2103 10/01/2012[/FONT]
[FONT="]10/01/2102 10/08/2010[/FONT]
[FONT="]10/08/2010 12/14/2007[/FONT]
[FONT="]
[/FONT]
[FONT="]The actual output is:[/FONT]
[FONT="]Yellow[/FONT][FONT="] Blue[/FONT]
[FONT="]11/23/2013 11/19/2013[/FONT]
[FONT="]11/19/2103 11/19/2013[/FONT]
[FONT="]10/01/2102 11/19/2013[/FONT]
[FONT="]10/08/2010 11/19/2013[/FONT]
[FONT="]11/23/2013 10/01/2102[/FONT]
[FONT="]11/19/2103 10/01/2102[/FONT]
[FONT="]10/01/2102 10/01/2102[/FONT]
[FONT="]10/08/2010 10/01/2102[/FONT]
[FONT="]The same pattern is repeated 2 more times with Blue values of 10/08/2010 and then 12/14/2007.[/FONT]
[FONT="]Here is the SQL:[/FONT]
[FONT="]
[/FONT]
[FONT="]SELECT Long_List.Yellow,Short_List.Blue[/FONT]
[FONT="]FROM [/FONT]
[FONT="]([/FONT]
[FONT="]SELECT DISTINCT BirthDate AS Blue[/FONT]
[FONT="]FROM ([/FONT]
[FONT="]SELECT DISTINCT BirthDate FROM citizens[/FONT]
[FONT="]UNION[/FONT]
[FONT="]SELECT DISTINCT DeathDate FROM citizens[/FONT]
[FONT="]WHERE DeathDate IS NOT NULL[/FONT]
[FONT="])[/FONT]
[FONT="]WHERE BirthDate <([/FONT]
[FONT="]SELECT MAX(Pink)[/FONT]
[FONT="]FROM [/FONT]
[FONT="]([/FONT]
[FONT="]SELECT DISTINCT BirthDate AS Pink[/FONT]
[FONT="]FROM ([/FONT]
[FONT="]SELECT DISTINCT BirthDate FROM citizens[/FONT]
[FONT="]UNION[/FONT]
[FONT="]SELECT DISTINCT DeathDate FROM citizens[/FONT]
[FONT="]WHERE DeathDate IS NOT NULL[/FONT]
[FONT="])[/FONT]
[FONT="])[/FONT]
[FONT="])[/FONT]
[FONT="]ORDER BY BirthDate DESC[/FONT]
[FONT="]) AS Short_List[/FONT]
[FONT="],[/FONT]
[FONT="]([/FONT]
[FONT="]SELECT DISTINCT BirthDate AS Yellow[/FONT]
[FONT="]FROM ([/FONT]
[FONT="]SELECT DISTINCT BirthDate FROM citizens[/FONT]
[FONT="]UNION[/FONT]
[FONT="]SELECT DISTINCT DeathDate FROM citizens[/FONT]
[FONT="]WHERE DeathDate IS NOT NULL[/FONT]
[FONT="])[/FONT]
[FONT="]WHERE BirthDate > ([/FONT]
[FONT="]SELECT MIN(Red)[/FONT]
[FONT="]FROM[/FONT]
[FONT="]([/FONT]
[FONT="]SELECT DISTINCT BirthDate AS Red[/FONT]
[FONT="]FROM ([/FONT]
[FONT="]SELECT DISTINCT BirthDate FROM citizens[/FONT]
[FONT="]UNION[/FONT]
[FONT="]SELECT DISTINCT DeathDate FROM citizens[/FONT]
[FONT="]WHERE DeathDate IS NOT NULL[/FONT]
[FONT="])[/FONT]
[FONT="])[/FONT]
[FONT="])[/FONT]
[FONT="]ORDER BY BirthDate DESC[/FONT]
[FONT="]) AS Long_List[/FONT]
[FONT="]ORDER BY Short_List.Blue DESC,Long_List.Yellow DESC[/FONT]
[/FONT]
[FONT="]
[/FONT]
[FONT="]The desired output is:[/FONT]
[FONT="]Yellow[/FONT][FONT="] Blue[/FONT]
[FONT="]11/23/2013 11/19/2013[/FONT]
[FONT="]11/19/2103 10/01/2012[/FONT]
[FONT="]10/01/2102 10/08/2010[/FONT]
[FONT="]10/08/2010 12/14/2007[/FONT]
[FONT="]
[/FONT]
[FONT="]The actual output is:[/FONT]
[FONT="]Yellow[/FONT][FONT="] Blue[/FONT]
[FONT="]11/23/2013 11/19/2013[/FONT]
[FONT="]11/19/2103 11/19/2013[/FONT]
[FONT="]10/01/2102 11/19/2013[/FONT]
[FONT="]10/08/2010 11/19/2013[/FONT]
[FONT="]11/23/2013 10/01/2102[/FONT]
[FONT="]11/19/2103 10/01/2102[/FONT]
[FONT="]10/01/2102 10/01/2102[/FONT]
[FONT="]10/08/2010 10/01/2102[/FONT]
[FONT="]The same pattern is repeated 2 more times with Blue values of 10/08/2010 and then 12/14/2007.[/FONT]
[FONT="]Here is the SQL:[/FONT]
[FONT="]
[/FONT]
[FONT="]SELECT Long_List.Yellow,Short_List.Blue[/FONT]
[FONT="]FROM [/FONT]
[FONT="]([/FONT]
[FONT="]SELECT DISTINCT BirthDate AS Blue[/FONT]
[FONT="]FROM ([/FONT]
[FONT="]SELECT DISTINCT BirthDate FROM citizens[/FONT]
[FONT="]UNION[/FONT]
[FONT="]SELECT DISTINCT DeathDate FROM citizens[/FONT]
[FONT="]WHERE DeathDate IS NOT NULL[/FONT]
[FONT="])[/FONT]
[FONT="]WHERE BirthDate <([/FONT]
[FONT="]SELECT MAX(Pink)[/FONT]
[FONT="]FROM [/FONT]
[FONT="]([/FONT]
[FONT="]SELECT DISTINCT BirthDate AS Pink[/FONT]
[FONT="]FROM ([/FONT]
[FONT="]SELECT DISTINCT BirthDate FROM citizens[/FONT]
[FONT="]UNION[/FONT]
[FONT="]SELECT DISTINCT DeathDate FROM citizens[/FONT]
[FONT="]WHERE DeathDate IS NOT NULL[/FONT]
[FONT="])[/FONT]
[FONT="])[/FONT]
[FONT="])[/FONT]
[FONT="]ORDER BY BirthDate DESC[/FONT]
[FONT="]) AS Short_List[/FONT]
[FONT="],[/FONT]
[FONT="]([/FONT]
[FONT="]SELECT DISTINCT BirthDate AS Yellow[/FONT]
[FONT="]FROM ([/FONT]
[FONT="]SELECT DISTINCT BirthDate FROM citizens[/FONT]
[FONT="]UNION[/FONT]
[FONT="]SELECT DISTINCT DeathDate FROM citizens[/FONT]
[FONT="]WHERE DeathDate IS NOT NULL[/FONT]
[FONT="])[/FONT]
[FONT="]WHERE BirthDate > ([/FONT]
[FONT="]SELECT MIN(Red)[/FONT]
[FONT="]FROM[/FONT]
[FONT="]([/FONT]
[FONT="]SELECT DISTINCT BirthDate AS Red[/FONT]
[FONT="]FROM ([/FONT]
[FONT="]SELECT DISTINCT BirthDate FROM citizens[/FONT]
[FONT="]UNION[/FONT]
[FONT="]SELECT DISTINCT DeathDate FROM citizens[/FONT]
[FONT="]WHERE DeathDate IS NOT NULL[/FONT]
[FONT="])[/FONT]
[FONT="])[/FONT]
[FONT="])[/FONT]
[FONT="]ORDER BY BirthDate DESC[/FONT]
[FONT="]) AS Long_List[/FONT]
[FONT="]ORDER BY Short_List.Blue DESC,Long_List.Yellow DESC[/FONT]