×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

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

Help with SQL

Help with SQL

Help with SQL

(OP)
Hi,

I have two tables (table1 and table2). They both contain two fields (ID and state). What I would like is to list all the ID's in table1 that are either not in table2 or if the ID is in table2 to see if the state in table1 is not in table2 with matching ID's.

For example in table1 you have an ID of 1234 and a state of IL. In table2 if 1234 is not there to list it or if 1234 is in table2 and table2 has 1234 IN, 1234 OK, 1234 OR to list the ID because it does not have 1234 IL.

I have tried several different ways with not luck. Could someone please help me out.

Thanks,

Mark
 

RE: Help with SQL

SELECT T1.ID, T1.state, T2.state
FROM table1 T1 LEFT JOIN table2 T2
ON T1.ID = T2.ID
WHERE COALESCE(T2.state,') <> T1.state

smile

r937.com | rudy.ca
Buy my new book Simply SQL from Amazon

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