I almost finished my system until I noticed that a product had a different sku with another supplier (I have more than 15,000 products in the table table_prices
from 7 different suppliers, it is assumed that they all have to handle the same SKU
(but they don't), I came up with adding sku2
to solve, but I got into a black hole.
Now taking advantage of the fact that I can get help from you, I would like to be able to search in the table table_prices
for the lowest price if the sku, sku2, upc or ean matches table_products
, in this way I will not have a major problem if a supplier decides to put a bad sku
since I will have more information to relate.
I leave a link with what I have working ... I look for sku of table_products
and I get the lowest price of table_prices
http://sqlfiddle.com/#!9/47809f/1/0
I hope to get $90 on product 1
SELECT p.*, x.supplier AS supplier, x.price , x.quantity AS quantity
FROM table_prices x
JOIN
(SELECT sku,
MIN(price) price
FROM table_prices
WHERE quantity != 0 AND active = 1
GROUP BY sku) y
ON y.sku = x.sku
AND y.price = x.price
JOIN table_products p
WHERE p.sku = x.sku
ORDER BY category, price
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…