I have this query
SELECT COUNT(device_id) AS count,devices.created_by,users.name
FROM devices
INNER JOIN users ON devices.created_by = users.email
GROUP BY created_by
which returns three users.
Problem is, I have 5 users (two of them haven’t done anything)
Can I get a query which would also include them to show that they have done nothing?
coalesce(device_id,0) converts NULL to 0
Don’t inner-join when you want all of the results from one of the tables.
1 Like
r937
December 6, 2020, 10:38am
4
that’s harsh, man
you’re going to make him think about which table
harsh, i say
oh yesm this is what a RIGHT JOIN is for, right?
SELECT COUNT(device_id) AS count,devices.created_by,users.name
FROM devices
RIGHT JOIN users ON devices.created_by = users.email
GROUP BY created_by
cause it only returns 4 users
oh, it worked if I GROUP BY users.name
r937
December 6, 2020, 9:52pm
7
dear mr/mrs/miss/ms lurtnowski (as the case may be), you need to do some testing on your own before coming back here
right join? left join? WHAT’S THE DIFFERENCE!!
also, decide what column you should actually be grouping on
test all these out yourself, please
1 Like
r937
December 6, 2020, 10:26pm
8
ah, i see you figured it out while iwas replying
well done
1 Like
system
Closed
March 8, 2021, 5:26am
9
This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.