Select first row in each group using group by in sqlite Select first row in each group using group by in sqlite sqlite sqlite

Select first row in each group using group by in sqlite


The following works for me with your sample table data:

SELECT MaxOfStatecountpercent, statepoolnumber, STATECODEFROM geoviewGROUP BY statepoolnumberHAVING MIN(ROWID)ORDER BY ROWID

This assumes that, based on your desired input, you want the 'first' state of each statepoolnumber group to be the first record (rather than 'first' by alphabetical order).