-1

This question already has an answer here:

I have two tables, one containing all the quantities of products by country and another table that contains the prices by country.

When I add a condition for example country = "ch", I have the price correct for this country, I want to return different prices for all countries. How can I do that?

Here's my query:

SELECT 
    items.prod,
    items.qty_fr,
    items.date,
    products.price
FROM items
LEFT JOIN products
    ON products.product = items.prod
WHERE
    products.country = "CH"
GROUP BY
    items.prod

This is the result of my query:

It returns the first value

enter image description here

Here's my first table:

enter image description here

My second table :

enter image description here

marked as duplicate by Paul White Sep 17 '15 at 14:22

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

0

Not sure if this is what you are looking for:

SELECT 
    products.country,
    items.prod,
    max(items.date) AS ItemDate,
    sum(products.price) AS ProductPrice 
FROM items
LEFT JOIN products on products.product = items.prod
group by products.country , items.prod

To add any more columns use an aggregation (sum, max etc) if its a numerical value else put it in the GROUP BY list

Not the answer you're looking for? Browse other questions tagged or ask your own question.