Use twice DISTINCT ON ina multiple join situation
If I understand correctly a product can have more than one image/video an of course more than one category.

In this case you can use a LATERAL JOIN and limit the result to only one row.

I've set up one small fiddle just to show you:




select p.id,
       p.name,
       i.image,
       v.channel,
       v.url,
       c.name
from   products p
left join lateral (select id, image
                   from   image
                   where  product_id = p.id
                   limit  1) i on true
left join lateral (select id, channel, url
                   from video
                   where product_id = p.id
                   limit 1) v on true
left join lateral (select c.id, c.name 
                   from   categoryproduct cp
                   join   category c
                   on     cp.category_id = c.id
                   where  cp.product_id = p.id
                   limit 1) c on true;



id | name  | image | channel | url  | name
-: | :---- | :---- | :------ | :--- | :---
 1 | prod1 | img1  | c1      | url1 | cat1
 2 | prod2 | img3  | c3      | url3 | cat3



db&lt;>fiddle here