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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T22:22:15+00:00 2026-06-16T22:22:15+00:00

I need help to write a simple procedure. Let me explain what I’m trying

  • 0

I need help to write a simple procedure. Let me explain what I’m trying to do.

I have 3 tables

  1. tJobOffer
  2. tApplication
  3. tApplicationStatus

I would like to create a procedure that return me a list of tJobOffer with the number of candidate that responded to this tJobOffer. Candidate is a status of my table tApplicationStatus. This table is linked to tApplication that is linked to tJobOffer. An application can be CANDIDATE / ACCEPTED / REFUSED / IGNORED / …

I created this query :

    SELECT 
        [T].[JobOfferId],
        [T].[JobOfferTitle],
        COUNT([A].[ApplicationId]) AS [CandidateCount]

    FROM        [tJobOffer] AS [T]
    LEFT JOIN   [tApplication] AS [A]
        ON      [A].[JobOfferId] = [T].[JobOfferId]
    LEFT JOIN   [tApplicationStatus] AS [S]
        ON      [S].[ApplicationStatusId] = [A].[ApplicationStatusId]
        AND     [S].[ApplicationStatusTechnicalName] = 'CANDIDATE'

    GROUP BY
            [T].[JobOfferId],
            [T].[JobOfferTitle]
            --[A].[ApplicationStatusId]

    ORDER BY [T].[JobOfferTitle]

The result is

> 52ED7C67-21E1-49BB-A1F8-0601E6EED1EA  Annonce 1   0
> F26B228D-0C81-4DA8-A287-F8F997CC1F9C  Annonce 1b  0
> 9DA60B23-F113-4C7F-9707-2B90C1556D5D  Announce 25 2
> 258E11A7-79C1-47B6-8C61-413AA54E2360  Announce 3  0
> DA582383-5DF4-4E1D-837C-382371BDEF57  Announce 6  2

This is not correct because I only have 1 candidate for Announce 6. If a set my line

    --AND     [S].[ApplicationStatusTechnicalName] = 'CANDIDATE'

in comment the result is the same. My query seems to ignore this line. What is wrong?

EDIT —

My correct result should be

> 52ED7C67-21E1-49BB-A1F8-0601E6EED1EA  Annonce 1   0
> F26B228D-0C81-4DA8-A287-F8F997CC1F9C  Annonce 1b  0
> 9DA60B23-F113-4C7F-9707-2B90C1556D5D  Announce 25 2
> 258E11A7-79C1-47B6-8C61-413AA54E2360  Announce 3  0
> DA582383-5DF4-4E1D-837C-382371BDEF57  Announce 6  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-06-16T22:22:16+00:00Added an answer on June 16, 2026 at 10:22 pm

    I guess you want this:

    SELECT 
        [T].[JobOfferId],
        [T].[JobOfferTitle],
        COUNT([A].[ApplicationId]) AS [CandidateCount]
    
    FROM        [tJobOffer] AS [T]
    LEFT JOIN   [tApplication] AS [A]
        INNER JOIN  [tApplicationStatus] AS [S]
            ON      [S].[ApplicationStatusId] = [A].[ApplicationStatusId]
            AND     [S].[ApplicationStatusTechnicalName] = 'CANDIDATE'
        ON      [A].[JobOfferId] = [T].[JobOfferId]
    
    GROUP BY
            [T].[JobOfferId],
            [T].[JobOfferTitle]
    
    ORDER BY [T].[JobOfferTitle] ;
    

    You could also join first the 2 “Application” tables, group by and then join the derived table with JobOffer:

    SELECT 
        [T].[JobOfferId],
        [T].[JobOfferTitle],
        COALESCE([G].[Cnt], 0) AS [CandidateCount]
    
    FROM        [tJobOffer] AS [T]
    LEFT JOIN   
                ( SELECT 
                      [A].[JobOfferId],
                      COUNT(*) AS [Cnt]
    
                  FROM        [tApplication] AS [A]
                  INNER JOIN  [tApplicationStatus] AS [S]
                      ON      [S].[ApplicationStatusId] = [A].[ApplicationStatusId]
                      AND     [S].[ApplicationStatusTechnicalName] = 'CANDIDATE'
    
                  GROUP BY
                              [A].[JobOfferId]
                ) AS [G]
        ON      [G].[JobOfferId] = [T].[JobOfferId]
    
    ORDER BY [T].[JobOfferTitle] ;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need help to write a simple procedure. Let me explain what I'm trying
I need help with something that seems simple but confuses me. Trying to write
Need help with a query that I wrote: I have three tables Company id
I need help from the Regex wizards out there. I am trying to write
We have a database of loyalty card holders. I'm trying to write a simple
I need help with how to write a SQL Server 2005 query to handle
I need some help in getting this right, problem Write a function which takes
need help/guide for sql select query, I have 2 table stock and stock_history, in
I need to write simple routine in iphone arm assembly (under xcode 4) (normal
I have a coding/maths problem that I need help translating into C#. It's a

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.