Mysql
 sql >> Database >  >> RDS >> Mysql

Query MySQL valore minimo

Puoi utilizzare una sottoquery per identificare il min(a) valore per ogni id e poi uniscilo di nuovo al tuo tavolo:

select *
from yourtable t1
inner join
(
  select min(A) A, id
  from yourtable
  group by id
) t2
  on t1.id = t2.id
  and t1.A = t2.A

Vedi SQL Fiddle con demo

Il risultato è:

| ID | A |     B |
------------------
| 10 | 5 |  blue |
| 20 | 2 | black |
| 30 | 7 |   red |