[thelist] Query Logic

Casey Crookston caseyb at thecrookstons.com
Tue Feb 19 22:50:06 CST 2008


Spot on Joshua.  Thank you.

----- Original Message ----- 
From: "Joshua Olson"


>> -----Original Message-----
>> From: Casey Crookston
>> Sent: Tuesday, February 19, 2008 11:30 PM
>>
>> What I need, however, is only the first row per each new
>> store.  Or....
>>
>> ID     Store        Description
>> 1       StoreA     description1
>> 4       StoreB     description4
>
> Casey,
>
> This is a common question (that I for some reason always feel obligated to
> answer!).  It looks like you are using "the lowest id" to designate the
> "first" record within a group.  See these posts for more information:
>
> http://lists.evolt.org/archive/Week-of-Mon-20020318/107145.html
> http://lists.evolt.org/archive/Week-of-Mon-20040223/156066.html
>
> Basic takeaway from those posts:
>
> Find the id corresponding to the minimum record within each group then 
> join
> back to the table to get the details:
>
> SELECT *
> FROM myTable
> INNER JOIN
> (
>  SELECT Min(id) AS id
>  FROM myTable
>  GROUP BY Store
> ) drvtable
> ON drvtable.id = myTable.id
>
> Joshua 




More information about the thelist mailing list