Select A.data_id, A.products_id, B.quantity, B.image
from data A
inner join product B on A.products_id = B.products_id
inner join (select A.data_id, min(A.products_id) as products_id
from data A
inner join product B on A.products_id = B.products_id
inner join (select A.data_id, max(B.quantity) as max_quantity
from data A
inner join product B on A.products_id = B.products_id
group by A.data_id) C on A.data_id = C.data_id and B.quantity = C.max_quantity
Group by A.data_id) D on A.data_id = D.data_id and A.products_id = D.products_id;
|