×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Selecting Unique values between 2 tables

Selecting Unique values between 2 tables

Selecting Unique values between 2 tables

(OP)
Hey, I've been trying to get this working for awhile now and haven't come up with anything. Here's a picture representing the data to give you a better idea.

Table1
-----------
PK    Index1    Index2
1       C          D
2       C          F
3       C          H

Table2
-----------
PK    Index1    Index2
1       C         D
2       C         S

What I'm trying to do is union these two tables on Index1. That would give 5 results. After that I want to check if any rows in Table2 have any Index2 values that match those in Table1. In this case, there is 1. If there is a match, then discard the row in Table1, keeping the row in Table2 leaving us with 4 results. I've tried using the UNION, INNER/LEFT/RIGHT JOIN, experimenting with many different combination's but can't seem to get it. Anyone have any ideas? I'm not sure if this is poor table design or I'm just missing something in my SQL statement. Thanks

RE: Selecting Unique values between 2 tables

you cannot union two tables "on" a particular column --  a union is performed on all columns

what does "discard the row in table 1" mean?  after a UNION, there is only a result set, and no longer any "row in table 1"

yes, your table design does seem to be questionable, if these are permanent tables, because they appear to have the same layout/function/purpose

r937.com | rudy.ca

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close