I have a database that has three tables, RMA, Orders, and Customer and I am trying to count the returns(RMAs) by the State(which is in the customer's table). The query keeps returning only one record though (UTAH counted only).

I have a database that has three tables, RMA, Orders, and Customer and I am trying to count the returns(RMAs) by the State(which is in the customer's table). The query keeps returning only one record though (UTAH counted only).

Copyright © 2021 Jogjafile Inc.
Your query is missing a
group byclause that aggregates records bystate. In all other databases other than MySQL, you would get a syntax error... But unfortunately MySQL is lax about that (when optionONLY_FULL_GROUP_BYis disabled), which makes this kind of error harder to spot.Note that I used table aliases to shorten the query, and changed the count to a simple
count(*)(which is equivalent in the query, and more efficient for the database).If you want to display states that have no returns, then you can use
left joins instead: