Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6890817
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:19:49+00:00 2026-05-27T06:19:49+00:00

I am having issues with the following stored procedure query. I have 3 tables:

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T06:19:49+00:00Added an answer on May 27, 2026 at 6:19 am

    Your select statement should look like this:

    SELECT d.prop_id, d.prop_title, a.acnt_id
       , SUM(CASE
                WHEN u.prop_id IS NOT NULL THEN 1
                ELSE 0
             END) AS UnitCount
    FROM #prop_details AS d
    INNER JOIN #prop_account AS a ON d.prop_id = a.prop_id
    LEFT JOIN #prop_unit AS u ON d.prop_id = u.prop_id
    GROUP BY d.prop_id, d.prop_title, a.acnt_id
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can't find the solution. I'm having the following stored procedure: CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_process_upload_log`(
One of the developers in my team is having the following issues. They have
I am having issues with the following code which loads an SQLite database. -
Hi I am having issues with the following and it crashes the iPhone simulator,
Following on from my earlier question , I am still having issues with loading
I am having following issue with reading binary file in C. I have read
I'm designing a mySQL DB and I'm having the following issue: Say I have
I'm having an issue with rails involving javascript. Basically, I have the following code:
I'm having some serious performance issues with a multi-million row table that I feel
I am having a problem with an update stored procedure. The error is: UPDATE

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.