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 

Comments

Popular posts from this blog

curl - PHP fsockopen help required -

HTTP/1.0 407 Proxy Authentication Required PHP -

c# - Resource not found error -