This question is complicated so examples would work best…I have the following table on ODBC, not SQL server Management
NAME SEQNUM JOHN 2 JOHN 4 JOHN 7 MARY 12 MIKE 4 MIKE 9 PETER 7 PETER 12
So, i want to pull back one name with the lowest seqNum…
NAME SEQNUM JOHN 2 MARY 12 MIKE 4 PETER 7
This data will not work with SELECT (MIN(SEQNUM)). That returns a number. I want the actual data to put in my dataset. Does ANYONE know how to do that?
Re. Dems’ comment:
If you simply use
GROUP BY namethen your select-list can only includenameand the aggregate functionMIN(). It’s often the case that you really want the whole row where the minimum value occurs per group.If you use the
TOPsolution (orLIMITif you use MySQL, PostgreSQL, SQLite), then you can’t get the minimum for multiple groups based onname, you can only get the minimum for onename.I read between the lines of the OP’s question and guessed that they want the whole row, that there are more columns than those shown in the question (there always are), and that the desired query should return results for multiple names, not just one.
Re. SquareCog’s comment:
The solution you suggest is also a join:
However, this solution probably can’t use indexes to evaluate the join, whereas the solution I gave can.