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

The Archive Base Latest Questions

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

I did previously ask a question about this, but must admit was biased against

  • 0

I did previously ask a question about this, but must admit was biased against SQL based solutions and now I can’t find the question, so I’ll try again, phrase it carefully and be much more open to any solutions provided.

I have two tables:

tblCurrent 
 Ref  | CustomerID | ... .. .. .  . |
X001
X002
X003


tblHistorical 
 Ref   | ... .. .. .  . |  Missing | Matched
X001   | ... .. .. .  . |  TRUE    | FALSE
X001   | ... .. .. .  . |  FALSE   | FALSE
X002   | ... .. .. .  . |  TRUE    | TRUE
X002   | ... .. .. .  . |  TRUE    | FALSE
X003   | ... .. .. .  . |  FALSE   | FALSE
X003   | ... .. .. .  . |  TRUE    | TRUE

Ref is unique in tblCurrent, but not in Historical.

How can I construct a view, that is based on tblCurrent that results in three additional columns that count the number of records in tblHistorical that:

  • match the Ref AND Missing is TRUE

  • match the Ref AND Missing is False

  • match the Ref AND Matched is True

Note that I will need to add additional columns that count the number of records in tblHistorical based on similar criteria.

  • 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-11T06:54:50+00:00Added an answer on June 11, 2026 at 6:54 am

    I think you need to use LEFT JOIN on this since it is possible that sometime ref may not exist on tblHistorical table.

    SELECT  a.ref,
            SUM(CASE WHEN b.Missing = 'True' THEN 1 ELSE 0 END) missingTrue,
            SUM(CASE WHEN b.Missing = 'False' THEN 1 ELSE 0 END) missingFalse,
            SUM(CASE WHEN b.Matched = 'True' THEN 1 ELSE 0 END) matchTrue
    FROM    tblCurrent a
            LEFT JOIN tblHistorical b
                on a.ref = b.ref
    GROUP BY a.ref
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Did ask a question about the same problem here: Silly problem with UTF8 but
I tried to ask this question previously howver I did not recieve the correct
I previously did some popups / dialogs that I've now got regression error in
Previously I did a Tutorial on OpenGL-ES 1.0. For reference, this can be found
Did about 30 minutes worth of searching, found lots of relevant info, but none
I have to remind the user about schedules which he did previously in java.
I asked a question similar to this one a couple of weeks ago, but
How can I add a row to array using PDO. Previously i did it
Please refer my previous post here . I did changes accordingly but getting error.
Did you ever have the following situation: you need to store information, but a

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.