使用:
SELECT t1.*,
COALESCE(x.num_rows, 0) AS entries
FROM `table 1` t1
LEFT JOIN (SELECT t3.v_id,
COUNT(*) 'num_rows'
FROM `table_3` t3
GROUP BY t3.v_id) x ON x.v_id = t1.v_id
使用:
SELECT t1.*,
COALESCE(x.num_rows, 0) AS entries
FROM `table 1` t1
LEFT JOIN (SELECT t3.v_id,
COUNT(*) 'num_rows'
FROM `table_3` t3
GROUP BY t3.v_id) x ON x.v_id = t1.v_id