• python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Facebook Twitter Instagram
Devs Fixed
  • python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Devs Fixed
Home ยป Resolved: Left join with count group by not displaying all left tables null records

Resolved: Left join with count group by not displaying all left tables null records

0
By Isaac Tonny on 17/06/2022 Issue
Share
Facebook Twitter LinkedIn

Question:

I have two tables Broadcastlists and Contacts(foreign key of broadcastlist). I want to show broadcastlist tables all records and count of broadcastlistid in contacts table.
My Query:-
Broadcastlists:
Id Name
1 Test 1
2 Test 2
3 Test 4
4 Test 5

Contacts:
Id Name Broadcastlist_id
1 Rahul 2
2 Mansi 1
3 Nisha 2
4 Nidhi 2
5 Prashant 1

I want Output like this
Id Name Recepients(count)
1 Test 1 2
2 Test 2 3
3 Test 3 0
4 Test 4 0

But, Output come like this, shows only one null record from left table I want all null data from left table
Id Name Recepients(count)
1 Test 1 2
2 Test 2 3
3 Test 3 0

Answer:

You have grouped with a wrong column. Try this:
Output
id name Recepients
1 Test 1 2
2 Test 2 3
3 Test 4 0
4 Test 5 0

See this db<>fiddle.

If you have better answer, please add a comment about this, thank you!

count group-by left-join mysql sql
Share. Facebook Twitter LinkedIn

Related Posts

Resolved: Sort dataframe columns value by close it to another column

27/03/2023

Resolved: PostgreSQL resample 1 minute OHLCV candle data into 5 minute OHLCV candle data

27/03/2023

Resolved: How do I navigate a table without any easily accessible distinctions?

27/03/2023

Leave A Reply

© 2023 DEVSFIX.COM

Type above and press Enter to search. Press Esc to cancel.