SELECT DISTINCT r.*, k.tags FROM ratings as r
LEFT JOIN keywords as k ON r.movieid = k.movieid
SELECT DISTINCT * FROM ratings LEFT JOIN keywords USING (movieid)
SELECT t.id,
case
when t.idProduct = :id_product and t.relatedProduct <> :id_product
then p2.id
when t.relatedProduct = :id_product and t.idProduct <> :id_product
then p1.id
end as product_id,
case
when t.idProduct = :id_product and t.relatedProduct <> :id_product
then p2.name
when t.relatedProduct = :id_product and t.idProduct <> :id_product
then p1.name
end as product_name,
case
when t.idProduct = :id_product and t.relatedProduct <> :id_product
then p2.sku
when t.relatedProduct = :id_product and t.idProduct <> :id_product
then p1.sku
end as product_sku
FROM relatedProduct AS t
INNER JOIN products p1 ON p1.id = t.idProduct
INNER JOIN products p2 ON p2.id = t.relProduct
where ( (t.idProduct = :id_product and t.relatedProduct <> :id_product)
or (t.relatedProduct = :id_product and t.idProduct <> :id_product))
SELECT t.id,
p.id product_id,
p.name product_name,
p.sku product_sku
FROM relatedProduct AS t
INNER JOIN products p ON p.id = case
when t.idProduct = :id_product and t.relatedProduct <> :id_product
then t.relatedProduct
when t.relatedProduct = :id_product and t.idProduct <> :id_product
then t.idProduct
end
-- в этом варианте запроса можно попытаться убрать where условие, так как условие inner join подавит неподходящие строки!
where ( (t.idProduct = :id_product and t.relatedProduct <> :id_product)
or (t.relatedProduct = :id_product and t.idProduct <> :id_product))