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

  • Home
  • SEARCH
  • 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 8351779
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T08:45:00+00:00 2026-06-09T08:45:00+00:00

I was wondering if someone could help me understand what this code is doing.

  • 0

I was wondering if someone could help me understand what this code is doing. I have inhereted a SQL script and I’m trying to update the code so it’s easier to read. I’ve looked at the below code and it seems like there’s an easier way to do this, but I can’t wrap my head around what this code is actually doing. Could anyone help me just describe this code? (Maybe clue me into how to do this with a subquery or EXISTS or an easier way to read this?

SELECT DISTINCT
    s.id
    ,f.FLAG1
    ,f.FLAG1
    ,f.FLAG1
INTO #DLK_TEMP
from Inner_Source D
    LEFT OUTER JOIN Outer_Source_1 S on D.au = S.AU 
        AND D.wcv_entity_key = S.wcv_entity_key 
    LEFT OUTER JOIN Outer_Source_2 F on S.id = F.id
WHERE S.id IS NOT NULL 
  • 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-09T08:45:01+00:00Added an answer on June 9, 2026 at 8:45 am

    It seems strange that it’s performing an LEFT OUTER JOIN on S and then testing for those rows where the join succeeds. It should be an INNER JOIN instead. And if S.ID is not nullable then you can also remove the WHERE clause.

    SELECT DISTINCT
        s.id
        ,f.FLAG1
        ,f.FLAG1
        ,f.FLAG1
    INTO #DLK_TEMP
    FROM Inner_Source AS D
    JOIN Outer_Source_1 AS S
        ON D.au = S.AU 
        AND D.wcv_entity_key = S.wcv_entity_key 
    LEFT OUTER JOIN Outer_Source_2 AS F
    ON S.id = F.id
    

    If you like, you can change the first join to an EXISTS clause to make it clear that the join is only acting as a filter:

    SELECT DISTINCT
        s.id
        ,f.FLAG1
        ,f.FLAG1
        ,f.FLAG1
    INTO #DLK_TEMP
    FROM Outer_Source_1 AS S
    LEFT OUTER JOIN Outer_Source_2 AS F ON S.id = F.id
    WHERE EXISTS
    (
        SELECT *
        FROM Inner_Source AS D
        WHERE D.au = S.AU 
        AND D.wcv_entity_key = S.wcv_entity_key
    )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was wondering if someone could help me with this. I have defined my
I was wondering if someone could help me understand this problem. I prepared a
I was wondering if someone could help me. Im trying to integrate some code
I have an SQL problem i was wondering if someone could help me out.
I was wondering if someone could help me with this SQL statement? Say, I
Wondering if someone could help me. I have next to no knowledge with Ajax,
Just wondering if someone could help me with a very simple SQL query. I
was wondering if someone could help with this one. This is the first time
Im wondering if someone could help me. I have hundreds of people uploading images
I was wondering if someone could help me get pointers to solve this problem.

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.