Get max ID of each item in a list

Get max ID of each item in a list

am 10.09.2010 19:12:05 von bcantwell

--=-evmLH1MeHWoL98ZcB8z/
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: 7bit

I have a simple table

mytable
id int
time_stamp tiemstamp
value int
tid int

I want to find the max id for each individual tid in my table.

if I did it one by one it would be:
select max(id) from mytable where tid = 12345;

but how can I do something more like:
select concat(tid,':',id) from mytable where tid in (123,124,125,126);

Above is obviously wrone, because what I want is 1 row for each tid in
my 'in' clause that is the max id for that tid.:

tid:id -> 123:8 for instance.

Maybe a group by or something?


--=-evmLH1MeHWoL98ZcB8z/--

Re: Get max ID of each item in a list

am 10.09.2010 19:15:29 von Kevin

SELECT tid,max(id) FROM mytable
GROUP BY tid

Le 10 sept. 2010 =E0 19:12, Bryan Cantwell a =E9crit :

> I have a simple table=20
>=20
> mytable=20
> id int
> time_stamp tiemstamp
> value int
> tid int
>=20
> I want to find the max id for each individual tid in my table.
>=20
> if I did it one by one it would be:
> select max(id) from mytable where tid =3D 12345;
>=20
> but how can I do something more like:
> select concat(tid,':',id) from mytable where tid in (123,124,125,126);
>=20
> Above is obviously wrone, because what I want is 1 row for each tid in
> my 'in' clause that is the max id for that tid.:
>=20
> tid:id -> 123:8 for instance.
>=20
> Maybe a group by or something?
>=20

--=20
K=E9vin Lab=E9cot






--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/mysql?unsub=3Dgcdmg-mysql-2@m.gmane.o rg