Count times ID appears in a table and return in row.

Posted by Tyler on Stack Overflow See other posts from Stack Overflow or by Tyler
Published on 2010-04-29T07:09:39Z Indexed on 2010/04/29 7:17 UTC
Read the original article Hit count: 364

Filed under:
|
|
|
|
SELECT
Boats.id, Boats.date, Boats.section, Boats.raft, 
river_company.company, river_section.section AS river 
FROM Boats 
INNER JOIN river_company ON Boats.raft = river_company.id 
INNER JOIN river_section ON Boats.section = river_section.id 
ORDER BY Boats.date DESC, river, river_company.company

Returns everything I need. But how would I add a [Photos] table and count how many times Boats.id occurs in it and add that to the returned rows.

So if there are 5 photos for boat #17 I want the record for boat #17 to say PhotoCount = 5

© Stack Overflow or respective owner

Related posts about sql

Related posts about mssql