sql - MySQL selecting MAX unique values -



sql - MySQL selecting MAX unique values -

i have mysql table shows sellers table looks following:

advertiseid[pk] | customerid[fk] | productsid[fk] | quantites_advertised | price_advertised ------------------------------------------------------------------------------------------ 1 2 2 4.00 2.00 2 4 3 5.00 2.50 3 3 2 1.00 1.00

the first record means ..this means client id 2 selling choclates(product id 1), 4kg's@ £2.00

i wanted select each product id query displays minimum of different products: hence, table be:

advertiseid[pk] | customerid[fk] | productsid[fk] | quantites_advertised | price_advertised ------------------------------------------------------------------------------------------ 2 4 3 5.00 2.50 3 3 2 1.00 1.00

the query outputs min cost product 2 , 3 since product 3 product cheapest cost , product 2 min between 4.00 , 1.00 1.00 hence, outputted. have various different products how able accomplish this? have tried query incorrect.:

select c.fname p.productname, s.productid, s.quantity, s.price sellers s, products p, client c s.price = (select min(price) sellers p.id=s.productid , c.id=s.cid);

anyone have thought how can accomplish expected output?

you utilize filtering inner join:

select * yourtable yt bring together ( select productsid , min(price_advertised) min_price_advertised yourtable grouping productsid ) filter on filter.productsid = yt.productsid , filter.min_price_advertised = yt.price_advertised

mysql sql distinct max

Comments

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -