php - SQL query to select only the maximum items? -
i have table: want search uid
id | vid | uid 1 | 1 | 5 1 | 1 | 6 1 | 2 | 6 2 | 3 | 5 2 | 3 | 6 2 | 4 | 6
i want end result:
id | vid | uid 1 | 2 | 6 2 | 4 | 6
in other words, select entries vid max of uid keeping in min nid differ. suppose:
select * table uid = 6 , max(vid)
???
but doesn't work?
one way order value in descending order (so max @ top), select first result.
select t.id, t.vid, t.uid table t t.id = 1 order t.vid desc limit 1
or mean want all rows t.vid highest value? in case this,
select t.id, t.vid, t.uid table t t.id = 1 , t.vid = (select max(vid) table);
edit: based on edit question, looks want max vid value each id? if i'm understanding correctly, should give need.
select t.id, max(t.vid) vid, t.uid table t t.uid = 6 group t.id
Comments
Post a Comment