0

I have Two tables with following structure

details
---------------
id | session_id
1    1
2    1
3    1

details_extra
---------------
id | details_id
1    1
2    1
3    2
4    3

Output I am looking for is -

output
---------------
id  | subscribers(count)
1     2
2     1
3     1

The query I am writing is -

select id, count(details_extra.id) from details left join details_extra on
details_id = details.id where session_id='1';

output I get is

{id:1, subscribers:4} 

Can any one please help.

Edit - Got it working by adding a Group By.

3

1 Answer 1

0

Try to group by id:

select id, count(details_extra.id) from details left join details_extra on
details_id = details.id where session_id='1' group by id;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.