Mysql unique values query -
i have table name-value pairs , additional attribute. same name can have more 1 value. if happens want return row has higher attribute value.
table:
id | name | value | attribute 1 | set1 | 1 | 0 2 | set2 | 2 | 0 3 | set3 | 3 | 0 4 | set1 | 4 | 1
desired results of query:
name | value set2 | 2 set3 | 3 set1 | 4
what best performing sql query desired results?
this solution perform best:
select ... table t left join table t2 on t2.name = t.name , t2.attribute > t1.attribute t2.id null
another solution may not perform (you need evaluate against data):
select ... table t not exists ( select 1 table t2 t2.name = t.name , t2.attribute > t.attribute )
Comments
Post a Comment