|
|
Subject:
Simple SQL Question
Category: Computers > Programming Asked by: snep-ga List Price: $2.00 |
Posted:
25 Aug 2005 17:40 PDT
Expires: 24 Sep 2005 17:40 PDT Question ID: 560572 |
|
Subject:
Re: Simple SQL Question
Answered By: hammer-ga on 29 Aug 2005 10:04 PDT Rated: |
Snep-ga, Depending on what version of which engine you end up with, there are a couple of ways to do this. The simplest is to use a LEFT OUTER JOIN: SELECT t1.*, t2.* FROM t1 LEFT JOIN t2 ON t1.i1 = t2.i2 WHERE t2.i2 IS NULL; You can also use NOT EXISTS or NOT IN in a subselect, again, depending on what is available in your version. SELECT i1 FROM t1 WHERE NOT EXISTS (SELECT * FROM t2 WHERE t1.i1 = t2.i2); Detailed usage on these techniques and more can be found at Sames Publishing. Sams Publishing MySQL SQL Syntax and Use http://www.samspublishing.com/articles/article.asp?p=30875&seqNum=5&rl=1 - Hammer Search strategy ---------------- mySQL "outer join" unmatched |
snep-ga
rated this answer:
thanks for the great answer hammer. Appreciate your help. |
|
Subject:
Re: Simple SQL Question
From: abdulmuqsith-ga on 26 Aug 2005 07:50 PDT |
You can try following; Persons who don't work for any employer don't appear in mapping table. Thus the following query can work. select person_name from person where person_id NOT IN (Select person_id from map_table) |
Subject:
Re: Simple SQL Question
From: snep-ga on 26 Aug 2005 08:41 PDT |
Hi Abdul, Thanks for your response. I am not sure if your query would work since I feel "NOT IN" is not a valid parameter of SQL Select query. If you find any reference for this online, please let me know. Thanks. |
Subject:
Re: Simple SQL Question
From: meridius-ga on 26 Aug 2005 10:46 PDT |
I back up Abdul on his statement, with this page from the MySQL reference docs: http://dev.mysql.com/doc/mysql/en/comparison-operators.html (It would help to use the find feature on your browser, searching for the string "NOT IN".) His query would work. Hopefully that helps. |
Subject:
Re: Simple SQL Question
From: hammer-ga on 26 Aug 2005 12:07 PDT |
snep, There are different "flavors" of SQL. Which version of which database engine are you using? MySQL, SQL Server, Access, Oracle...? - Hammer |
Subject:
Re: Simple SQL Question
From: klashk-ga on 26 Aug 2005 16:13 PDT |
Depends on the DBMS in use, maybe try: SELECT DISTINCT person_id FROM Persons MINUS SELECT DISTINCT person_id FROM Emplotment |
If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you. |
Search Google Answers for |
Google Home - Answers FAQ - Terms of Service - Privacy Policy |