SELECT master_table.productID,
master_table.name,
CASE WHEN ads_table.adsID IS NULL THEN 0 ELSE 1 END AS ads_flag
FROM master_table
LEFT JOIN ads_table
ON master_table.productID = ads_table.productID
SELECT master_table.productID,
master_table.name,
CASE WHEN ads_table.adsID IS NULL THEN 0 ELSE 1 END AS ads_flag
FROM master_table
LEFT JOIN ads_table
ON master_table.productID = ads_table.productID