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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T05:18:36+00:00 2026-05-24T05:18:36+00:00

Let say I have set 1: 1 30 60 2 45 90 3 120

  • 0

Let say I have set 1:

1   30  60
2   45  90
3   120 240
4   30  60
5   20  40

and set 2

30  60
20  40

I would like to do some sort of union where I only keep rows 1,4,5 from set 1 because the latter 2 columns of set 1 can be found in set 2.

My problem is that set based operations insist on the same numnber of columns.

I’ve thought of concatenating the columns contents, but it feels dirty to me.

Is there a ‘proper’ way to accomplish this?

I’m on SQL Server 2008 R2

In the end, I would like to end up with

1   30  60
4   30  60
5   20  40

CLEARLY I need to go sleep as a simple join on 2 columns worked…. Thanks!

  • 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-24T05:18:36+00:00Added an answer on May 24, 2026 at 5:18 am

    You are literally asking for

    give me the rows in t1 where the 2 columns match in T2

    So if the output is only rows 1, 4 and 5 from table 1 then it is a set based operation and can be done with EXISTS or INTERSECT or JOIN. For the “same number of column”, then you simply set 2 conditions with an AND. This is evaluated per row

    EXISTS is the most portable and compatible way and allows any column from table1

    select  id, val1, val2
    from    table1 t1
    WHERE EXISTS (SELECT * FROM table2 t2
                      WHERE t1.val1 = t2.val1 AND t1.val2 = t2.val2)
    

    INTERSECT requires the same columns in each clause and not all engines support this (SQL Server does since 2005+)

    select  val1, val2
    from    table1
    INTERSECT
    select  val1, val2
    from    table2
    

    With an INNER JOIN, if you have duplicate values for val1, val2 in table2 then you’ll get more rows than expected. The internals of this usually makes it slower then EXISTS

    select  t1.id, t1.val1, t1.val2
    from    table1 t1
            JOIN
            table2 t2 ON t1.val1 = t2.val1 AND t1.val2 = t2.val2
    

    Some RBDMS support IN on multiple columns: this isn’t portable and SQL Server doesn’t support it

    Edit: some background

    Relationally, it’s a semi-join (One, Two).

    SQL Server does it as a “left semi join”

    INTERSECT and EXISTS in SQL Server usually give the same execution plan. The join type is a “left semi join” whereas INNER JOIN is a full “equi-join”.

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

Sidebar

Related Questions

I have a set of rows which I've fetched from a table. Let's say
Let's say that I have a set of relations that looks like this: relations
let's say I have a set of functions like, article() - outputs a article
Let say we have set of URLs like this yoursite.com/39827-key1-key2-key3 yoursite.com/132-key1-key2-key3 yoursite.com/9223455-key1-key2-key3 and so
Let's say you have some set of numbers with a known lower bound and
Let's say I have some arbitrary set of points connected by faces and lines
let's say I have this set of HTML-markup and CSS #CSS .inputhelp_text { background:
Let say I have to parse a hierarchical set of tags <tag> <subtag1 attr1=value1
I have two sets of vectors, set A and set B. Let's say set
Let say I have an array like: Array ( [0] => Array ( [Data]

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.