I will start off by posting my SQL code first-
table prefs -> userid catid pref_num pref
(users preferences, pref_num has a maximum of 3 therefore each user has the option of 3 preferences)
table sup_prices -> supplierid prodid price_each
(prices for each supplier)
table products -> prodid product catid
(table of products)
My aim is to select the minimum priced supplier for the products selected in the users preferences.
It seems to pull out the minimum prices but not the associated supplier?
Any ideas on where my query is incorrect? It has me stumpted, I have been looking at it for hours just cannot see the problem.
Code:
SELECT X.prodid, Y.product, X.supplierid, MIN( X.price_each ) AS minprice
FROM sup_prices X
INNER JOIN (
SELECT PP.prodid, PP.product
FROM products PP
INNER JOIN prefs PR ON PP.catid = PR.catid
AND PP.prodid = PR.pref
WHERE userid =1
)Y ON X.prodid = Y.prodid
GROUP BY X.prodid
table prefs -> userid catid pref_num pref
(users preferences, pref_num has a maximum of 3 therefore each user has the option of 3 preferences)
table sup_prices -> supplierid prodid price_each
(prices for each supplier)
table products -> prodid product catid
(table of products)
My aim is to select the minimum priced supplier for the products selected in the users preferences.
It seems to pull out the minimum prices but not the associated supplier?
Any ideas on where my query is incorrect? It has me stumpted, I have been looking at it for hours just cannot see the problem.