I know this has been posted before, but I can't find the previous threads so please bear with me...
I want to grab the very 1st record of each product in a table like this
ID   CLIENTID   PRODID
1     a                     1
2     b                     1
3     c                     1
4     a                     2
5     b                     2
6     c                     2
7     a                     3
8     b                     3
9     c                     3
so that I'd get a record set like:
ID   CLIENTID   PRODID
1     a                     1
4     a                     2
7     a                     3
Thanks for the hellp guru'sSELECT t1.ID, t1.CLIENTID, t1.PRODID
FROM table t1
INNER JOIN (
SELECT MIN(ID) AS ID, PRODID
FROM table
ORDER BY PRODID) t2 ON t1.ID = t2.ID
 AND t1.PRODID = t2.PRODID|||You did mean GROUP BY, not ORDER BY, right?
SELECT t1.ID, t1.CLIENTID, t1.PRODID
FROM table t1
INNER JOIN (
SELECT MIN(ID) AS ID, PRODID
FROM table
GROUP BY PRODID) t2 ON t1.ID = t2.ID
AND t1.PRODID = t2.PRODID|||Yep.  Been sniped.   (grin)|||Thanks guys, exactly what I was after. :)
Subscribe to:
Post Comments (Atom)
 
No comments:
Post a Comment