Hi all,
I have four tables:
product_offers
offerid product_name supplier_id price
product_info
id name description manufacturer_id
manufacturers
id name
suppliers
id name
What I want is to get a list of the lowest offer price for each product along with the relevant offer information for ANY offer of that product at that price, plus product manufacturer and offer supplier information
To put it another way:
I want a list showing offers, one for each product, at the lowest price available, from any ONE of the suppliers offering it at that price.
This is the latest incarnation of the query I am trying to wrestle into shape:
select o.product_name
, o.price
, o.offerid
from offers as o, products as p, manufacturers as m, suppliers as s
where o.product_name = p.name
AND p.manufacturerid = m.id
AND o.supplier_id = s.id
o.price =
( select min(o.price)
from offers as o2
where o2.product_name = o.product_name
)
group by o.product_name
order by o.product_name
...but as you'll see, this gives me the correct info for product name and price, but the value for offerid is junk, as is any information I try to pull from other tables.
I would appreciate any neat solutions to this using only mysql. I am thinking now that I'll just do it in two stages and use PHP to loop through results from an initial query to get the detail but I know that will be clumsy... any ideas anyone?
Many thanks in advance,
stoocoo