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.

 All Forums
 Other Forums
 MS Access
 INNER JOIN subquery SELECT

Author  Topic 

Dennisvm82
Starting Member

1 Post

Posted - 2011-07-28 : 09:53:52
Hi guys! I am trying to select some data from a table in an Access 2010 database. The thing was: I wanted to display the latest "Configuration" release of each System (adapter). Well, using the SQL code below it seems to work perfectly, but I am having trouble filtering out the "QaEnv", too.

This is what is displayed before the query:

ID | QaEnv | System | Type | Configuration | ActiveDate
1 | Delta (UAT2) EAI-V3 | MOMS Adapter | Adapter | 1.0 | 30-06-2011
2 | Delta (UAT2) EAI-V3 | GSG Adapter | Adapter | 1.1 | 30-06-2011
3 | Yankee (UAT1) ACC-V01 | MOMS Adapter | Adapter | 2.4 | 30-06-2011
4 | Delta (UAT2) EAI-V3 | GSG Adapter | Adapter | 1.0 | 20-06-2011
5 | Delta (UAT2) EAI-V3 | KIWI2 Adapter | Adapter | 1.7 | 30-06-2011
6 | Delta (UAT2) EAI-V3 | KIWI2 Adapter | Adapter | 1.5 | 20-06-2011

This is what is displayed after the query:

ID | QaEnv | System | Type | Configuration | ActiveDate
1 | Delta (UAT2) EAI-V3 | MOMS Adapter | Adapter | 1.0 | 30-06-2011
2 | Delta (UAT2) EAI-V3 | GSG Adapter | Adapter | 1.1 | 30-06-2011
3 | Yankee (UAT1) ACC-V01 | MOMS Adapter | Adapter | 2.4 | 30-06-2011
5 | Delta (UAT2) EAI-V3 | KIWI2 Adapter | Adapter | 1.7 | 30-06-2011

But I want to display this:

ID | QaEnv | System | Type | Configuration | ActiveDate
1 | Delta (UAT2) EAI-V3 | MOMS Adapter | Adapter | 1.0 | 30-06-2011
2 | Delta (UAT2) EAI-V3 | GSG Adapter | Adapter | 1.1 | 30-06-2011
4 | Delta (UAT2) EAI-V3 | KIWI2 Adapter | Adapter | 1.7 | 30-06-2011

SELECT t.*
FROM Deployments t
INNER JOIN
(
SELECT System, Max(ActiveDate) as ActDate
FROM Deployments
WHERE QaEnv = "Delta (UAT2) EAI-V3" AND Type = "Adapter"
AND (([ActiveDate] Between #6/20/2011# And #6/30/2011#))
GROUP BY System
)
x ON t.system = x.system AND t.ActiveDate = x.ActDate;


Can any of you help me out?

Thanks in advance,
Dennis

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2011-07-29 : 21:17:00
Add that in a where clause.

...
AND (([ActiveDate] Between #6/20/2011# And #6/30/2011#))
GROUP BY System
)
x ON t.system = x.system AND t.ActiveDate = x.ActDate
where t.QaEnv = "Delta (UAT2) EAI-V3";
Not quite clear to me whether I am misinterpreting the sample data. Alternatively, you could add QaEnv in the inner query (for example as max(QaEnv)) and then join on QaEnv in the outer query.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-07-30 : 01:42:07
[code]SELECT t.*
FROM (SELECT ROW_NUMBER() OVER (PARTITION BY system ORDER BY ActiveDate DESC,Configuration ASC) AS rn,* from Deployments) t
WHERE rn=1
[/code]

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -