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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T17:49:08+00:00 2026-06-11T17:49:08+00:00

my query is select m.year_id,Count(*) as Distinctions from NewTestDB.dbo.[Master_MARKS2005] as m join NewTestDB.dbo.Master_Student as

  • 0

my query is

select m.year_id,Count(*) as Distinctions from NewTestDB.dbo.[Master_MARKS2005] as m
join NewTestDB.dbo.Master_Student as s
on s.Student_id=m.Student_Id
join NewTestDB.dbo.Master_School as sc
on sc.school_id=s.school_code
where sc.SCHOOL_CODE= 'an0001' and m.YEAR_ID between 1 and 8 and m.[NRC_CLASS]='D'
group by m.year_id,

i want out of all year_id’s between 1 to 8 but now i am getting only when m.[NRC_CLASS]=’D’
how to rewrite this query so that i can get count as ‘0’ when no rows in the m.NRC_CLASS column contains ‘D’ value

  • 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-11T17:49:10+00:00Added an answer on June 11, 2026 at 5:49 pm

    You should use Left Join to achieve this

    Like you can try this

    SELECT m.year_id,COUNT(*) AS Distinctions 
           FROM NewTestDB.dbo.[Master_MARKS2005] AS m
    LEFT JOIN 
           NewTestDB.dbo.Master_Student AS s
    ON 
           s.Student_id=m.Student_Id
    JOIN 
           NewTestDB.dbo.Master_School AS sc
    ON 
           sc.school_id=s.school_code
    WHERE 
           sc.SCHOOL_CODE= 'an0001' 
           AND 
           m.YEAR_ID BETWEEN 1 AND 8 
           AND 
           m.[NRC_CLASS]='D' 
    GROUP BY m.year_id,
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have this simple query : SELECT YEAR(P.DateCreated) ,MONTH(P.DateCreated) ,COUNT(*) AS cnt FROM tbl1,
Query: SELECT u.user_id,r.totalVotes votes,r.totalPoints rating,@row:=@row+1 rank FROM mismatch_user u LEFT JOIN ratingItems r ON
Query: SELECT DISTINCT ([Equipment List].ID) AS Expr1, [Job Assignments].Job FROM [Equipment List] LEFT JOIN
this query SELECT * FROM tblContracts LEFT JOIN tblPartys ON tblContracts.id = tblPartys.Contract_id INNER
SQL query: SELECT ArticleCategories.Title AS Category, Articles.Title, Articles.[Content], Articles.Date FROM ArticleCategories INNER JOIN Articles
I have a query like: SELECT EXTRACT(WEEK FROM j.updated_at) as week, count(j.id) FROM jobs
I have a simple query: SELECT sds.district_id,detail.year, detail.race, SUM(count) FROM school_data_race_ethnicity_raw as detail INNER
Here is the query: SELECT name, SUM( `count` ) AS Total FROM `identdb` WHERE
I'm trying to optimize this slow query (>2s) SELECT COUNT(*) FROM crmentity c, mdcalls_trans_activity_update
I have this query SELECT semester, COUNT(id) AS total, RIGHT(RTRIM(semester), 4) AS year FROM

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.