I am having issues with the following stored procedure query.
I have 3 tables:
**table: prop_details**
prop_id | prop_title
1 | sun
2 | moon
3 | star
4 | mars
**table: prop_account**
prop_id | acnt_id
1 | 1
2 | 1
3 | 1
4 | 1
**table: prop_unit**
unit_id | prop_id
1 | 1
2 | 1
3 | 1
4 | 2
5 | 2
6 | 3
7 | 3
8 | 3
I am trying to gather the following output in the stored procedure:
prop_id | prop_title | acnt_id | unit_count
1 | sun | 1 | 3
2 | moon | 1 | 2
3 | star | 1 | 3
4 | mars | 1 | 0
Here is the SP I have, but it is only returning 1 row:
PROCEDURE `NewProc`(IN in_acntID int)
BEGIN
SELECT
*, COUNT(unit_id) AS unitCount
FROM
prop_units pu
RIGHT JOIN
prop_details pd
ON
pu.prop_id = pd.prop_id
RIGHT JOIN
prop_account pa
ON pd.prop_id = pa.prop_id
WHERE
pa.acnt_id = in_acntID;
END;
I am calling the sp like so: Call selPropertyByAcntID(@cntID) //@acntID = 1
Your select statement should look like this: