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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T14:19:32+00:00 2026-06-07T14:19:32+00:00

I was using the following query to try to find the differences between the

  • 0

I was using the following query to try to find the differences between the results of a queries of two databases. I am not able to use the AccountID as a compare point since they don’t line up between the different databases. The selects in the ctes both return 200105 rows but the result of the join on the cte has 201779 rows. The data in this case should be able to match up. Am I on the right track with this? If so what am I missing, or should I look to a different approach.

    with cteDev3 (AccountID, SecurityID, UniqueAccountID, BuyPrice, BuyDate, Shares)as
      (select Al.AccountID, al.SecurityID,ad.UniqueAccountId, BuyPrice, BuyDate, Shares
        from dev3TMAd.dbo.AccountLot al
        join dev3TMAd.dbo.AccountDetails ad
        on al.AccountID = ad.AccountId
        where ad.EnterpriseId = 'HuberFinancial'),
    cteTest2 (AccountID, SecurityID, UniqueAccountID, BuyPrice, BuyDate, Shares)as
       (select Al.AccountID, al.SecurityID,ad.UniqueAccountId, BuyPrice, BuyDate, Shares
        from test2TMAd.dbo.AccountLot al
        join test2TMAd.dbo.AccountDetails ad
        on al.AccountID = ad.AccountId
        where ad.EnterpriseId = 'HuberFinancial')

select c3.UniqueAccountId as 'Dev3' , t2.UniqueAccountId as 'Test2'
from cteTest2 t2
join cteDev3 c3
    on c3.UniqueAccountId = t2.UniqueAccountId
    and c3.SecurityID = t2.SecurityID
    and c3.BuyDate = t2.BuyDate
    and c3.Shares = t2.Shares
    and c3.BuyPrice = t2.BuyPrice

This is what the result sets look like for the subqueries that are part of the ctes:

AccountID | SecurityID | UniqueAccountId | BuyPrice | BuyDate | Shares
949662 | 17030 | 11284035 | 42.690021 | 2007-12-19 00:00:00 | 4.710000
949662 | 17030 | 11284035 | 42.690629 | 2007-12-19 00:00:00 | 13.521000
949662 | 17030 | 11284035 | 42.611940 | 2007-12-19 00:00:00 | 0.134000
949662 | 17030 | 11284035 | 39.323467 | 2008-03-10 00:00:00 | 0.946000
949662 | 17030 | 11284035 | 40.831884 | 2008-06-10 00:00:00 | 6.323000
949662 | 17030 | 11284035 | 30.730860 | 2008-09-09 00:00:00 | 6.335000
949662 | 17030 | 11284035 | 16.290063 | 2008-12-10 00:00:00 | 111.045000
950091 | 25885 | 11937183 | 14.629975 | 2012-03-23 00:00:00 | 12.337000
950091 | 25885 | 11937183 | 14.599671 | 2012-04-23 00:00:00 | 12.140000
950091 | 4325 | 11937183 | 11.082955 | 2012-01-27 00:00:00 | 6768.953000
950091 | 4325 | 11937183 | 11.119163 | 2012-01-31 00:00:00 | 1.242000
  • 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-07T14:19:33+00:00Added an answer on June 7, 2026 at 2:19 pm

    I think you want to do a full outer join, in order to find the ones that do not match:

    select (case when c3.UniqueAccountId is not null and t2.UniqueAccountId is not null
                 then 'MATCH'
                 when c3.UniqueAccountId is not null then 'DEV-ONLY'
                 when t2.UniqueAccountId is not null then 'TEST-ONLY'
                 else 'Oops!'
            end) as MatchType,
           c3.UniqueAccountId as 'Dev3', t2.UniqueAccountId as 'Test2'
    from cteTest2 t2 full outer join
         cteDev3 c3
         on c3.UniqueAccountId = t2.UniqueAccountId and
            c3.SecurityID = t2.SecurityID and
            c3.BuyDate = t2.BuyDate and
            c3.Shares = t2.Shares and
            c3.BuyPrice = t2.BuyPrice 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using the following HQL query to try and load a set of objects
I am using the following query to find out to top 6 viewed pages
I am using following query which works fine for me except one problem SELECT
using the following query in SQLDeveloper to test merge everything goes fine: merge into
Using the following query I am looking for a solution to get the latest
I'm using the following query to select users from my 'users' table with the
I am using the following query to select wait times from the table wait_times
I'm using the following query to extract the frequent short values from a mediumblob
i've been using the following query: select LEN(columnname) as columnmame from dbo.amu_datastaging This works,
I am using following SQL Query: SELECT `comment`.`id` AS `comment_id` , count( `comment_likes`.`comment_id` )

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.