Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
bretedward
Starting Member
7 Posts |
Posted - 2014-08-10 : 17:48:06
|
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. The desired output is:Yellow Blue11/23/2013 11/19/201311/19/2103 10/01/201210/01/2102 10/08/201010/08/2010 12/14/2007The actual output is:Yellow Blue11/23/2013 11/19/201311/19/2103 11/19/201310/01/2102 11/19/201310/08/2010 11/19/201311/23/2013 10/01/210211/19/2103 10/01/210210/01/2102 10/01/210210/08/2010 10/01/2102The same pattern is repeated 2 more times with Blue values of 10/08/2010 and then 12/14/2007.Here is the SQL:SELECT Long_List.Yellow,Short_List.BlueFROM (SELECT DISTINCT BirthDate AS BlueFROM (SELECT DISTINCT BirthDate FROM citizensUNIONSELECT DISTINCT DeathDate FROM citizensWHERE DeathDate IS NOT NULL)WHERE BirthDate <(SELECT MAX(Pink)FROM (SELECT DISTINCT BirthDate AS PinkFROM (SELECT DISTINCT BirthDate FROM citizensUNIONSELECT DISTINCT DeathDate FROM citizensWHERE DeathDate IS NOT NULL)))ORDER BY BirthDate DESC) AS Short_List,(SELECT DISTINCT BirthDate AS YellowFROM (SELECT DISTINCT BirthDate FROM citizensUNIONSELECT DISTINCT DeathDate FROM citizensWHERE DeathDate IS NOT NULL)WHERE BirthDate > (SELECT MIN(Red)FROM(SELECT DISTINCT BirthDate AS RedFROM (SELECT DISTINCT BirthDate FROM citizensUNIONSELECT DISTINCT DeathDate FROM citizensWHERE DeathDate IS NOT NULL)))ORDER BY BirthDate DESC) AS Long_ListORDER BY Short_List.Blue DESC,Long_List.Yellow DESC |
|
gbritton
Master Smack Fu Yak Hacker
2780 Posts |
Posted - 2014-08-10 : 18:48:04
|
duplicate of http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=195644 |
|
|
|
|
|