I have two tables, productsand meta. They relate to a 1: N ratio, where each product line has at least one meta line through a foreign key.
(namely: SQLfiddle: http://sqlfiddle.com/#!15/c8f34/1 )
I need to join these two tables, but I need to filter only unique products. When I try this query, everything is fine (4 lines returned):
SELECT DISTINCT(product_id)
FROM meta JOIN products ON products.id = meta.product_id
but when I try to select all columns, the DISTINCT rule no longer applies to the results, since 8 rows are returned instead of 4.
SELECT DISTINCT(product_id), *
FROM meta JOIN products ON products.id = meta.product_id
I tried many approaches, for example, trying to execute DISTINCTor GROUP BYin a subquery, but always with the same result.