MySQL - Join & Count rows from another table

前端 未结 3 806
轮回少年
轮回少年 2020-12-12 06:43

I have 3 tables, like:
parent(id, name)
children(id, data, parent_id, timestamp)
table_votes(id, user_id, child_id)

<
3条回答
  •  自闭症患者
    2020-12-12 07:27

    i am not sure if i am understanding your question correctly but to me it seems like you want to count the number of children in the tables_votes not in children. try the following:

    select id, data, parent_id, timestamp, child_id
    from table_votes join children on children_id.id = table_vote.child_id
    where child_id = (select count(child_id) from table_vote)
    and parent_id = '20'
    

提交回复
热议问题