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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:56:32+00:00 2026-05-26T19:56:32+00:00

I have a full join sql query and i am retrieving the data from

  • 0

I have a full join sql query and i am retrieving the data from the same table.the problem is i am getting the null value where i am expecting the column name.

Example:
I am having a table where there are two columns typeOfPost,dob.

DOB               TypeOfPost
---------      --------------
20/11/1998      Manager
1/1/2000         Sales
13/6/1999         Manager
20/1/1987         Manager
1/11/1985         Sales

Now when I am writing a join query like

select DATENAME(month,dob) as Red,count(TypeOfPost) 
from tablename
where TypeOfPost='Manager'
group by DATENAME(month,dob) as A



full join

select DATENAME(month,dob) as Green,count(TypeOfPost) 
from tablename
where TypeOfPost='Sales'
group by DATENAME(month,dob) as B on B.Green = A.Red



Output--                                                Expected Output--
---------------------                           ---------------------
Month      Man      Sal                           Month      Man      Sal
--------   -----   ------                        --------   -----   ------
January      1         1                              January      1         1
NULL         1         NULL                           June         1         NULL
November   1         1                              November   1         1

Now here the problem rise, I want ‘June’ in the column Month instead of NULL value.
So is there any way to get that??
Help me out.
Thanks.

  • 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-26T19:56:33+00:00Added an answer on May 26, 2026 at 7:56 pm

    One option is to

    • use a CASE statement in a subselect
    • Determine for given record if it is a manager or sales
    • substitute with 1 or 0 accordingly
    • SELECT and GROUP from this subselect the final results.

    SQL Statement

    SELECT  Month
            , SUM(Man) AS Man
            , SUM(Sal) AS Sal
    FROM    (        
              SELECT  DATENAME(MONTH, DOB) AS Month
                      , CASE WHEN TypeOfPost = 'Manager' THEN 1 ELSE 0 END AS Man
                      , CASE WHEN TypeOfPost = 'Sales' THEN 1 ELSE 0 END AS Sal
              FROM    tableName
            ) g          
    GROUP BY
            Month        
    

    or

    SELECT  Month
            , SUM(Man)
            , SUM(Sal)
    FROM    (        
              SELECT  DATENAME(MONTH, DOB) AS Month
                      , COUNT(TypeOfPost) AS Man
                      , 0 AS Sal
              FROM    tableName
              WHERE   TypeOfPost = 'Manager'
              GROUP BY
                      DATENAME(MONTH, DOB)
              UNION ALL         
              SELECT  DATENAME(MONTH, DOB) AS Month
                      , 0 AS Man
                      , COUNT(TypeOfPost) AS Sal
              FROM    tableName
              WHERE   TypeOfPost = 'Sales'
              GROUP BY
                      DATENAME(MONTH, DOB)
            ) g
    GROUP BY
            Month        
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a SQL Query with a join between several tables. When I run
I have the following SQL code: select val.PersonNo, val.event_time, clg.number_dialed from vicidial_agent_log val join
I have a SQL query of the form SELECT ... FROM A@DB1 a, B@DB1
I'm having a little problem getting SQL Server returning the same results as Oracle
I have this query: SELECT *, default_insurance.company AS company FROM (default_insurance) JOIN default_gruppe_rel ON
I've got a SQL query running a FULL JOIN on multiple database tables. The
Using SQL Server 2000. I have a table that receives a dump from a
Does Microsoft Access have Full Text Search? I know that MySQL and SQL Server
I have a full MS SQL Backup file that I would like to extract
We have a full text index on a fairly large table of 633,569 records.

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.