sql server - SQL query count elements in other table -
i have 2 sql tables, projects , milestones: projects pk -> proid milestones combined pk -> proid , mstno for reason cannot use proid foreign key link 2 tables (foreign key constraint). however, need write query show me details of of projects table records, number of milestones each project. can use inner join achieve somehow? i'm not writing sql queries. try 1 - select p.* , cnt = isnull(m.cnt, 0) dbo.projects p left join ( select proid, cnt = count(1) dbo.milestones group proid ) m on m.proid = p.proid