There is a query that the user has in the bookmarks this product, also considers the product likes and displays all products in the table:
SELECT P.*,
COUNT(L.USER_ID) AS LIKES,
(B.PRODUCT_ID = P.PRODUCT_ID AND B.USER_ID = B.USER_ID) AS BOOKMARKS
FROM PRODUCTS AS P
LEFT JOIN LIKES_PRODUCTS AS L ON (L.PRODUCT_ID = P.PRODUCT_ID)
LEFT JOIN BOOKMARKS_PRODUCTS AS B ON (B.PRODUCT_ID = P.PRODUCT_ID)
GROUP BY P.PRODUCT_ID, B.PRODUCT_ID, B.USER_ID ORDER BY P.PRODUCT_ID
But he adds the product to the existing ones in the product and does not display false
, but only true
, and false displays null
for its place:
product_id | product_name | ... | LIKES | BOOKMARKS |
------------------------------------------------------
1 | name 1 | ... | 0 | true |
1 | name 1 | ... | 0 | true |
2 | name 2 | ... | 0 | NULL |
3 | name 3 | ... | 0 | NULL |
4 | name 4 | ... | 0 | NULL |
Why does he add me an extra product 1 and does not display a bookmark column false
, but does it null
? Where am I wrong help me please.