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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T03:31:08+00:00 2026-06-19T03:31:08+00:00

Hello friends I have been using this query to select some two fields on

  • 0

Hello friends I have been using this query to select some two fields on my Java application.

select distinct STU_LEVEL, STU_STREAM from STUDENT_MASTER_TABLE where STATUS_YEAR !=ACADEMIC_YEAR

Problem is if there is no data, the application is throwing a null pointer Exception. I need it such that if the fields are Null, then they are defaulted to 0. I have tried this with Coalesce but I can’t seem to get it like:

select coalesce(distinct (STU_LEVEL,0),  (STU_STREAM, '0')) from STUDENT_MASTER_TABLE where STATUS_YEAR !=ACADEMIC_YEAR

Please help.

  • 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-19T03:31:09+00:00Added an answer on June 19, 2026 at 3:31 am

    You just need to use COALESCE twice like this:

    SELECT DISTINCT COALESCE(STU_LEVEL,0), COALESCE(STU_STREAM, '0')
    FROM STUDENT_MASTER_TABLE
    WHERE STATUS_YEAR !=ACADEMIC_YEAR
    

    This will return 0 for STU_Level if it is NULL and 0 for STU_Stream if it is NULL.

    SQL Fiddle Demo

    In response to your comment, it looks like you need to use a UNION get your desired results when no records are found:

    SELECT DISTINCT COALESCE(STU_LEVEL,0), COALESCE(STU_STREAM, '0')
    FROM STUDENT_MASTER_TABLE
    WHERE STATUS_YEAR !=ACADEMIC_YEAR
    UNION 
    SELECT 0,'0' FROM DUAL
    WHERE NOT EXISTS (
      SELECT DISTINCT COALESCE(STU_LEVEL,0), COALESCE(STU_STREAM, '0')
      FROM STUDENT_MASTER_TABLE
      WHERE STATUS_YEAR !=ACADEMIC_YEAR
    )
    

    And a sample fiddle: http://www.sqlfiddle.com/#!4/29039/1

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

Sidebar

Related Questions

hello friends I have some confusion in join query so for the same I
Hello Friends I am using a list box control in aspx page i have
Hello friends i have created two page one is index.html and second is about.html
Hello Friends i have the following query which defeat the very purpose. A day
Hello friends i have this class that is getting values from the database: import
Hello friends a newbie question... The Issue is like this: I have a static
Hello Friends. This is my demo game screen-shoot. Here i am using three buttons.
hello friends i have develop one application in which i have lots of images
Hello friends, I have a string like /Date(1312628727617+0000)/ and this regular expression convert into
possible duplicate Hello friends, I have seen many style files and see that some

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.