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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T05:36:15+00:00 2026-06-06T05:36:15+00:00

We are using a query that uses coalesce to compare potentially null values. I

  • 0

We are using a query that uses coalesce to compare potentially null values. I want to get away from this because not only does it make queries more difficult to maintain, it’s flat out ugly. Imagine this:

where coalesce(tbl1.field,'~') <> Coalesce(tbl2.field,'~')

…being repeated 30+ times in a where clause. Hecky nah.

I had been under the impression that EXISTS would allow me to circumvent this fugliness, but it turns out that I was wrong.

  • 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-06T05:36:17+00:00Added an answer on June 6, 2026 at 5:36 am

    The best alternative is to drive the coalesced value into your physical data model as a column default in place of NULL. This requires that the business accepts and understands that a token value will be substituted in the data model for whatever the business currently accepts NULL to represent. The tricky thing about NULL is sometimes accurately describing in your metadata and logical data model as to what NULL represents. It shouldn’t be permitted to mean multiple things from a purist standpoint. The other alternatives are work arounds to address the fact that NULL can not be compared to another value, NULL or not NULL.

    COALESCE is treated like an inline CASE statement in Teradata (and other databases for that matter). The trouble with numerous COALESCE statements in your WHERE clause is that the optimizer may not be accurately able to estimate the resulting cardinality because COALESCE allows more than two comparisons. COALESCE(A.Col1, B.Col2, C.Col3, '~') will return the first non-NULL value it encounters.

    You can eliminate NULLS from consideration if they are dimensions whose reference table does not have a NULL value in its domain. In other words, NULL is not a valid primary key. However, you will find in the optimizer that it will likely insert a condition on the table where NULLS are permitted to spool only those records where A.Col1 IS NOT NULL. So there is some overhead associated with NULL being permitted in your data model.

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

Sidebar

Related Questions

Context In our application, we snapshot data from a database using a query that
I have this query that inserts rows, using a subquery like so: INSERT INTO
I am using mssql and I want to make a query that returns a
I'm writing a Rails 3 ActiveRecord query using the where syntax, that uses both
In an ExtJS application that uses MVC design, how can you query records from
I am using this query: SELECT p.id, count(clicks.ip) FROM `p` LEFT JOIN c clicks
I have a SRSS report using a SQL Query that uses that FilteredViews to
How to fill multiple tables in a dataset. I m using a query that
Using Microsoft SQL server 2008 I have a query that is in need of
I have a query that I know can be done using a subselect, but

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.