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
 Access 2003 SQL Help Needed

Author  Topic 

MilesFromNowhere
Starting Member

1 Post

Posted - 2010-01-21 : 08:06:16
My SQL has never been very strong and this one has me stumped. Okay, I have two tables TableA and TableB. For each record in TableA there can be many in TableB. I have this SQL statement...

Select TableA.*, TableB.FieldX
From TableA, TableB
Where TableA.KeyNbr = TableB.KeyNbr
and TableB.Status IN ('X','T')
Order By TableA.Field3, TableB.FieldX, TableA.Field7, TableA.KeyNbr

Naturally what I get is multiple TableA records for each matching TableB record. Like this...



TableA.Field3 TableB.FieldX TableA.Field7 TableA.KeyNbr
--------------------------------------------------------
1 100 G B
1 100 G B
1 214 2 A
1 234 7 C
1 304 G B
1 315 2 A
1 315 2 A


What I really want is to get only one TableA record for the minimum value in TableB.FieldX so I would end up with...



TableA.Field3 TableB.FieldX TableA.Field7 TableA.KeyNbr
--------------------------------------------------------
1 100 G B
1 214 2 A
1 234 7 C

I hope I've explained this well enough to where someone can figure it out and lend a hand. Oh, in case this is important, I'm trying to create an updateable DAO recordset in VB6.
   

- Advertisement -