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

  • Home
  • SEARCH
  • 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 8073425
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T14:20:17+00:00 2026-06-05T14:20:17+00:00

I have three tables like this: Table 1 structure: Name: registered_applicant_details Fields: applicant_id INT

  • 0

I have three tables like this:

Table 1 structure:
Name: registered_applicant_details
Fields: applicant_id INT PRIMARY_KEY, state_id INT;

Table 2 structure:
Name: oc_shortlisted_candidates
Fields: candidate_id; >>> Which is a foreign Key refers to applicant_id in registered_applicant_details

Table 3 structure:
Name: oc_selected_candidates
Fields: candidate_id; >>> Which is a foreign Key refers to applicant_id in registered_applicant_details

I want result set like this : state_wise_counts

state_id | shortlisted_count | selected_counts

My approach to get the result is

Step 1: I have created two views like this

CREATE VIEW  state_wise_shortlisted_count AS 
    (select rad.state_id AS state_id,
             count(0) AS shortlisted 
      from (oc_shortlisted_candidates oec 
             join registered_applicant_details rad) 
      where (oec.candidate_id = rad.applicant_id) 
      group by rad.state_id);

CREATE VIEW state_wise_selected_count AS 
      (select rad.state_id AS state_id,
               count(0) AS selected 
      from (oc_selected_candidates oec 
            join registered_applicant_details rad)
      where (oec.candidate_id = rad.applicant_id) 
      group by rad.state_id);

Step 2: Now again joined those two views with state_id

SELECT s.state_id, sho.shortlisted, sel.selected
FROM statewise_shortlisted_count sho
JOIN statewise_selected_count sel ON sel.state_id = sho.state_id;

Drawbacks in my approach

As we have two foreign tables i.e. (shortlisted_candidates & selected_candidates) I am creating two view, but if we have like that some 10 tables means, I need to create 10 views.
So for “state_wise counts” we need to create 10 views,
If one more attribute i.e. “city” is present & if we want “city_wise_counts” again I need to create 10 more views.
I think this is not the right way.

Please suggest me with right solution.
Note: I don’t want to use sub-queries, because those tables have some 10,000 record & I need to reduce the number of db calls from application

  • 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-06-05T14:20:18+00:00Added an answer on June 5, 2026 at 2:20 pm

    Not sure what you mean about the performance of sub-queries. Your current code reads from the RAD table once for every count in your projection. How can sub-queries be any worse?

    Try something like this:

    select rad.state_id AS state_id
             ,  sum (case when oslc.candidate_id is not null then 1 else 0 end) AS shortlisted
             ,  sum (case when osec.candidate_id is not null then 1 else 0 end) AS selected
    from registered_applicant_details rad
         left outer join oc_shortlisted_candidates oslc 
              on (rad.applicant_id = oslc.candidate_id) 
         left outer join oc_selected_candidates osec  
              on (rad.applicant_id = osec.candidate_id) 
    group by rad.state_id;
    

    Caveat: untested code!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have three tables like this: Person table: person_id | name | dob --------------------------------
I have three tables...users, user_info, and quota_levels. They look like this: CREATE TABLE users
I have a typical N-M relationship structure like this: two independent tables: Table Client:
I have three tables: videos, videos_categories, and categories. The tables look like this: videos:
I have three tables. The designs were like student table create table student (studID
I have a SQL database with two tables like this: Users Id (PK) Name
Lets say that I have a database structure with three tables that look like
I have two tables: CATEGORY and SUBCATEGORY Table Structure for CATEGORY category_id int(11) category_name
Hi there I have an SQL table that looks like this: CREATE TABLE IF
I have a table like this: <table id='inventory_table'> <tr id='no_items_avail'> <td> There are no

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.