Answer the question
In order to leave comments, you need to log in
How to select records from one table and count records in JOIN tables, and what to do if there are no records?
The question is the following.. let's say there are 2 records in the advertising table with id_advert = 1 and id_advert = 2 in the click_advert and views_advert tables there are records only for id_advert = 1. How to get information for advertising id 2 .. where, respectively, count views and count clicks will be 0
SELECT count(distinct id_view) as views, count(distinct id_click) as clicks, advertising.* FROM advertising LEFT JOIN views_advert ON advertising.id_advert = views_advert.id_advert LEFT JOIN click_advert ON advertising.id_advert = click_advert.id_advert
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question