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 7736797
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T07:50:06+00:00 2026-06-01T07:50:06+00:00

for the table below tenant_id | status_id ———————- 3 | 6 ——————— 5 |

  • 0

for the table below

tenant_id | status_id
----------------------
   3      |   6
---------------------
   5      |   7
---------------------
   7      |   7
--------------------
   3      |   7
-------------------
   3      |   7
--------------------
   5      |   7

we can see that:

  • tenant_id=3 has 1 record with status_id=6
  • tenant_id=5 has 2 record with status_id=7
  • tenant_id=7 has 1 record with status_id=7
  • tenant_id=3 has 2 record with status_id=7

For given STATUS_ID_PARAM I want to get all tenants that has the most records with that STATUS_ID_PARAM.
For the example above, for STATUS_ID_PARAM = 7, the query should return 2 records:

   tenant_id | status_id
   --------------------
      3      |   7
   --------------------
      5      |   7

because those tenants has the most records(2 for each one) with status_id=7.

I tried something like this, but I don’t know how to continue or may be there is another way:

select tenant_id, count(status_id) s
from candidate
where status_id = STATUS_ID_PARAM 
group by tenant_id, status_id
  • 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-01T07:50:07+00:00Added an answer on June 1, 2026 at 7:50 am

    This will work in both Oracle and SQL Server

    select tenant_id, s
    from
      (       
        select tenant_id,
               count(*) as s,
               rank() over(order by count(*) desc) as rn
        from candidate
        where status_id = 7
        group by tenant_id
      ) T
    where rn = 1;
    

    (Tested on SQL Server 2005->2012 and Oracle 11g R2)

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

Sidebar

Related Questions

Lets say I have the table below. I want to get all the friends,
The table below displays all words in the string $commentstring . How can I
Given the example table below, how can I retrieve the high and low range
Notice that for the given table below, the first row or the first many
I have such table (below). I want to get someone's detail information if someones
How can I return a list of fields from a given table that contain
In the table below, the entire cells are hyperlinks. How can I make just
See the below table: col1 col2 ---- ---- 1 | a 2 | b
In the HTML table below, I would like to add a third column that
I have a website that does inserts into this table below. I need to

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.