I have the following three tables :
----PRODUCT----
PRODUCT_ID DESC
1 'Pencil'
2 'Paper'
----PRICE_BY_SUPPLIER----
PRODUCT_ID SUPPLIER_ID PRICE
1 1 10
1 2 9
1 3 9.5
2 1 5
----IMAGES_BY_PRODUCT----
PRODUCT_ID NAME
1 'pencil.img'
1 'pen.img'
1 'pencil_other.img'
2 'paper.img'
I would like a query that pull the minimum price, the count of supplier that hold the product and one image (one image among all suppliers). The output query should look like this:
----FINAL_QUERY----
PRODUCT_ID MIN_PRICE IMAGE SUPPLIER_COUNT
1 9 'pencil.img' 3
2 5 'paper.img' 1
I have this query that return everything except the image.
SELECT f.PRODUCT_ID, f.DESC, x.MIN_PRICE, x.SUPPLIER_COUNT
FROM (
SELECT pp.PRODUCT_ID,
MIN(pp.PRICE) AS MIN_PRICE,
COUNT(pp.PRODUCT_ID) AS SUPPLIER_COUNT
FROM PRICE_BY_SUPPLIER AS pp
GROUP
BY pp.PRODUCT_ID
)
AS x
INNER JOIN PRODUCT AS f
ON f.PRODUCT_ID = X.PRODUCT_ID
Can you help me complete my query ?