Thursday

SQL update with join : update table with count from another table

let's say we have two tables connected like this:
SELECT a.saved_list_id, COUNT(b.saved_list_entry_id)
FROM saved_list a
LEFT OUTER JOIN saved_list_entry b ON (a.saved_list_id = b.saved_list_id)
GROUP BY a.saved_list_id;

so update will be looking like follows:
update saved_list p JOIN saved_list_entry c ON p.saved_list_id = c.saved_list_id
SET p.`number_entries` = (SELECT count(saved_list_entry_id) as number_entries
FROM saved_list_entry c where c.saved_list_id = p.saved_list_id)

No comments:

here is powershell script on how to get list of files from changesets associated with one tfs task

$dllPath = "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\...