[thelist] Query Logic
Joshua Olson
joshua at waetech.com
Tue Feb 19 22:43:11 CST 2008
> -----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
<><><><><><><><><><>
Joshua L. Olson
WAE Technologies, Inc.
Augusta, Georgia Web Design
http://www.waetech.com/
Phone: 706.210.0168
Fax: 707.988.0168
Private Enterprise Number: 28752
Portfolio:
http://www.waetech.com/design/portfolio/
Monitor bandwidth usage on IIS6 in real-time:
http://www.waetech.com/services/iisbm/
More information about the thelist
mailing list