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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:20:56+00:00 2026-05-27T17:20:56+00:00

I feel a little silly asking this, because its probably realy simple. Select DISTINCT

  • 0

I feel a little silly asking this, because its probably realy simple.

Select DISTINCT ID from tbl1
    where col2='abc'
            ...
    and ID not in (select distinct tbl2.ID from tbl2 where tbl2.Dtm > '2010-01-01')

This is part of my upsert in TSQL so Id need to run the tbl2 where clause again (I used to use merge but its not available in this DB). The problem here is tbl2 has millions of rows and tbl1 has tens of thousands. Obviously running like this as tb1xtbl2 itd be extremely inefficient. Ive thought of using cursors and temp tables but I dont see that running much better ?

Anyone got other ideas?

  • 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-05-27T17:20:56+00:00Added an answer on May 27, 2026 at 5:20 pm

    There are several different ways to define this type of query.

    Please create queries with Left Join, Not In and Not Exists and check the execution plan, Only then you will know, which one is better suited for your case.

    Left Outer Join Way

    Select Distinct ID
    FROM tbl1 t1
    LEFT OUTER JOIN tbl2 on t1.ID = t2.ID and t2.DTM > '2010-01-01'
    WHERE
    t1.Col2 = 'abc'
    AND t2.ID IS NULL
    

    Reference:

    Similar Discussion Thread

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

Sidebar

Related Questions

I feel a little silly asking this question, but from everything I've read, this
I feel a little bit silly asking this, but I haven't been able to
I feel a little silly for asking this since I seem to be the
I feel a little silly asking this but I wanted everyones opinion on it.
I actually feel a little embarrassed asking this because it feels about as basic
I feel a little stupid asking this, but the Debug-menu in my Visual Studio
This is a very basic question. I feel kind of silly asking about it
This is my first MFC application away from VC6, and I feel a little
Feel silly asking this question, since this should be easy, but I can't figure
I'm a seasoned programmer and therefore feel a little embarrassed asking this question 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.