mysql - Select rows with the same Item name and show lowest Price -


We have two tables:

  product IDs. Items | Supplier 1 | Harry Potter | Warner 2 | Harry Potter | Warner 3 | Throne game HBO 4 | The Simpsons | Warner 5 | The Simpsons | Warner   

and

  value ID. Price 1 | 10.9 9 2 20.00 3. 20.00 4 10.00 5 | 12.00   

I am trying to get the lowest price item where there are two items with the same name and supplier.

I can find those rows where duplicates are as follows:

  SELECT Products.ID, Products.Item, excluding products.Supplier, Prices.price products Prices at Price Id = product. Id where the product. ID IN (Item ID from the item where Supplier = "Warner" group item has been counting (*)> 1)   

How can I modify only this I duplicate item name ?

I tried to order but it throws an error for me.

The result should be:

  id. Items | Supplier | Price 1 | Harry Potter | Warner | 10.9 9 4 The Simpsons | Warner | 10.00   

Thanks,

Rick

All your implementation of tables must be improved in the first place if your product table has the ID as the primary key, then your data will be as follows (you need the primary key).

  Product IDs. Items | Supplier 1 | Harry Potter | Warner 2 | Throne game HBO Value ID | Price 1 | 10.99 1 20.00 2. 20   

Now use the minimum task to select minimum prices

  SELECT Products.ID, Products.Item, Products.Supplier, MIN ( Prices.price) Prices at the left price from the products. Id = Products.ID;    

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -