T-SQL Select and count from different table?

前端 未结 2 1231
南方客
南方客 2020-12-19 02:47

I have a table (Threads) containing a field (id). I would like to select every row from Threads, as well as the number of rows in the

2条回答
  •  独厮守ぢ
    2020-12-19 03:29

    Sure - something like this?

    SELECT 
        t.ThreadID,
        (SELECT COUNT(*) FROM dbo.Posts p WHERE p.ThreadID = t.ThreadID)
    FROM
        dbo.Threads t
    

提交回复
热议问题