Simple SQL Select Query Question:: 8 posts - Last post: Mar 21, 2008Hi, I'm trying to return all of rows by applying a simple query to my database, however not all of the rows are being returned. http://webforumz.com/databases/66152-simple-sql-select-query-question.htmHOME | I am looking for a SQL Query for the below described problem:
There are two entities - Person and Employer. They have a many to many
relationship between them. To map such a relationship between Person
Table and Employer table, we have made use of a mapping table which
has 2 columns, one with person_id and other having Employer_ID. My
question is, I want a query which will return back a list of Persons
who don't work for any employer.
We plan to use either Oracle or MySql.
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 simple SQL question - CodingForums.com:: New Coder. Join Date: Aug 2006. Posts: 14. Thanks: 0. Thanked 0 Times in 0 Posts . juanc is an unknown quantity at this point. simple SQL question http://www.codingforums.com/showthread.php?t=131477HOME | Application Generation: A SImple SQL Question . . .:: A series of occasional musings on architecting, securing, optimizing and generating web based applications. By Peter Bell.: A SImple SQL Question . . . http://www.pbell.com/index.cfm/2007/4/21/A-SImple-SQL-Question---HOME |
Where's The Advantage In Windows Genuine Advantage?
Stocks Bounce After S&P Joins Bear Market
|