Select count of rows in another table in a Postgres SELECT statement

后端 未结 5 1453
我在风中等你
我在风中等你 2020-12-23 16:23

I don\'t know quite how to phrase this so please help me with the title as well. :)

I have two tables. Let\'s call them A and B. The

5条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-23 16:42

    To answer my own question:

    SELECT a.id, a.other_column, ..., 
    (SELECT COUNT(*) FROM b where b.a_id = a.id) AS b_count
    FROM a;
    

提交回复
热议问题