SELECT Tasks.id, name,
TYPE , run_time, template, config, parameters, policy, DATE_FORMAT( create_time, '%%Y-%%m-%%d %%T' ) AS create_time, owner, version,
IF( cnt IS NULL ,0,cnt)
AS count
FROM Tasks
LEFT JOIN
(
SELECT id, COUNT( * ) AS cnt
FROM TaskData
GROUP BY id
)idcount
ON Tasks.id = idcount.id