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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T20:08:04+00:00 2026-06-04T20:08:04+00:00

By taking reference from here I had made the following query: SELECT INSTITUTE.ID INST_ID,

  • 0

By taking reference from here

I had made the following query:

SELECT INSTITUTE.ID INST_ID,
  INSTITUTE.PLACEMENT PLACEMENT,
  INSTITUTE.ADDRESS INSTITUTE_LOCATION,
  COUNT(DISTINCT INSTITUTE_DEPARTMENT.id) departments
--  COUNT(DISTINCT INSTITUTE_CAMPUS.id) campuses
FROM INSTITUTE
LEFT JOIN INSTITUTE_DEPARTMENT
ON (INSTITUTE.id = INSTITUTE_DEPARTMENT.institute_id)
LEFT JOIN INSTITUTE_COURSE
ON (INSTITUTE.ID = INSTITUTE_COURSE.INSTITUTE_ID)
LEFT JOIN INSTITUTE_CAMPUS
ON (INSTITUTE.ID                       = INSTITUTE_CAMPUS.INSTITUTE_ID)
WHERE INSTITUTE.ID                     = 1761
AND INSTITUTE.IS_ACTIVE                = 1
AND INSTITUTE.IS_DELETED               = 0
AND INSTITUTE.DELETED_DATE            IS NULL
--AND INSTITUTE_CAMPUS.IS_ACTIVE         = 1
--AND INSTITUTE_CAMPUS.IS_DELETED        = 0
--AND INSTITUTE_CAMPUS.DELETED_DATE     IS NULL
AND INSTITUTE_DEPARTMENT.IS_ACTIVE     = 1
AND INSTITUTE_DEPARTMENT.IS_DELETED    = 0
AND INSTITUTE_DEPARTMENT.DELETED_DATE IS NULL
GROUP BY INSTITUTE.ID, INSTITUTE.PLACEMENT, INSTITUTE.ADDRESS

I am getting proper count of department field.

INST_ID | PLACEMENT | INSTITUTE_LOCATION | DEPARTMENTS
 1761     NIIT           Noida              2 

But by including campus count(campus count is 0 on this insitute_id), I am getting null rows.

In short, when count are o null rows are returned while rows are returned when count are greater than 0.
  • 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-04T20:08:05+00:00Added an answer on June 4, 2026 at 8:08 pm

    You should put your campus conditions in LEFT JOIN condition not in where condition. If you put in where it filters your compaus table. Try this

    SELECT INSTITUTE.ID INST_ID,
    INSTITUTE.PLACEMENT PLACEMENT,
    INSTITUTE.ADDRESS INSTITUTE_LOCATION,
    COUNT(DISTINCT INSTITUTE_DEPARTMENT.id) departments
    COUNT(DISTINCT INSTITUTE_CAMPUS.id) campuses
    FROM INSTITUTE
    LEFT JOIN INSTITUTE_DEPARTMENT
    ON (INSTITUTE.id = INSTITUTE_DEPARTMENT.institute_id)
    LEFT JOIN INSTITUTE_COURSE
    ON (INSTITUTE.ID = INSTITUTE_COURSE.INSTITUTE_ID)
    LEFT JOIN INSTITUTE_CAMPUS
    ON (INSTITUTE.ID                       = INSTITUTE_CAMPUS.INSTITUTE_ID AND INSTITUTE_CAMPUS.IS_ACTIVE = 1 AND INSTITUTE_CAMPUS.IS_DELETED = 0 AND INSTITUTE_CAMPUS.DELETED_DATE IS NULL)
    WHERE INSTITUTE.ID                     = 1761
    AND INSTITUTE.IS_ACTIVE                = 1
    AND INSTITUTE.IS_DELETED               = 0
    AND INSTITUTE.DELETED_DATE            IS NULL
    AND INSTITUTE_DEPARTMENT.IS_ACTIVE     = 1
    AND INSTITUTE_DEPARTMENT.IS_DELETED    = 0
    AND INSTITUTE_DEPARTMENT.DELETED_DATE IS NULL
    GROUP BY INSTITUTE.ID, INSTITUTE.PLACEMENT, INSTITUTE.ADDRESS
    

    This works!

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

Sidebar

Related Questions

I had made custom example by taking reference from here Example is working fine
I had made Spring MVC and Hibernate application by taking reference from here on
Here's the question first: Is this possible? I'm taking my inspiration from Joe Wrobel's
I'm JOINing the results of this query: SELECT twitter_personas.id , 'TwitterPersona' , twitter_personas.name FROM
Taking a look at my question HERE , I now want to return the
When taking a database from a relatively un-normalized form and normalizing it, what, if
I was taking a look at the assert() reference page and I got stuck
Taking Sql this quarter and not having any luck with the following question: The
I already saw this post here (http://stackoverflow.com/questions/1398113/sql-select-one-row-randomly-but-taking-into-account-a-weight), but couldnt work it out. Where do
I have recently inherited a large web project. Before taking this on, I had

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.