I have this SQL query which is causing me to struggle a little bit.
SELECT c.Threat_Type, COUNT(*) FROM BORE.NormalToilet c
LEFT JOIN BORE.EnragedToilet p on p.Toilet_ID = c.Toilet_ID
GROUP BY c.Threat_Type
Here's the output:
+--------------+--------+
| Threat Type | Count |
+--------------+--------+
| Portable | 26 |
| Japanese | 1 |
| Toilet | 1 |
| Assassin | 3 |
+--------------+--------+
Now here's the problem with this query:
- There are, correctly, 26 vulnerabilities in our portable toilet firmware.
- There is, incorrectly listed, 1 vulnerability in our Japanese toilet... there are no vulnerabilities, only requested features. This should say
0, not1. - Same problem as above: Toilet features have no vulnerabilities.
If I try an INNER JOIN, it doesn't include the fields with 1. This is the correct behavior (as there are no matches), however, I want it to say 0 instead of 1. Using a LEFT JOIN, it just says 1, which is heinously incorrect.
What am I doing wrong?
count(p.Toilet_ID)left jointhe row would contain anullvalue in one of the columns. As you are doing acount(*)it would count the entire row. so you get1. Usecount(somecolumnname)instead/.vkp, if you're interested in getting a correct answer checked, I will accept it.