I’m currently using the following query to determine which projects in a database have no associated milestones:
SELECT P.project_id, COUNT(M.milestone_id) as count FROM projects P
LEFT JOIN milestones M USING(project_id)
GROUP BY P.project_id
HAVING count < 1
and it returns:
project count
---------------
9 0
34 0
32 0
41 0
How do I now go INSERT a new milestone row for each project_id in that table?
You can use the
INSERT...SELECTstatementchange
tableNAmeto the name of the table where you want to insert the new row/s.UPDATE 1
now question arises, what if you want to have a value which is not present in the column? you can create virtual values for that.