Groups | Blog | Home
all groups > sql server (alternate) > may 2004 >

sql server (alternate) : ms access query problem


Jimmy Tran
5/13/2004 4:36:34 PM
Hi Everyone,

I am doing a small database in ms access. I have two tables: One has all
the information such as name, address, phone number, and etc. The second
table contains the keyID of the first table and some additional
information about the data in the first table( But not every record in
the first table will have additional information).
Something like this:
TABLE1:
KeyID Name Major
1 Jack PreMed
2 Tom Engineering
3 Susan Writing

TABLE2:
KeyID GPA Year
1 3.5 1999
1 3.4 2000
3 2.9 2000

When I use query:
Select Table1.Name, Table1.Major, Table2.GPA, Table2.Year
From Table1 inner join Table2 on Table1.KeyID = Table2.KeyID

I am only getting records that exists in both tables. How can I change
this query so that I will get all records from Table1 and all records
from Table2. Like this:

Name Major GPA Year
Jack PreMed 3.5 1999
Jack PreMed 3.4 2000
Tom Engineering
Susan Writing 2.9 2000

Thank you a lot for helping me out.

Jim

*** Sent via Developersdex http://www.developersdex.com ***
Jimmy Tran
5/13/2004 5:36:36 PM
Thank You Guys!!!

*** Sent via Developersdex http://www.developersdex.com ***
David Portas
5/13/2004 5:57:32 PM
[quoted text, click to view]

But you are posting in a Microsoft SQLServer newsgroup...

[quoted text, click to view]

It's called an OUTER join. Lookup OUTER JOINs in the Access help file:

SELECT Table1.Name, Table1.Major, Table2.GPA, Table2.Year
FROM Table1
LEFT JOIN Table2
ON Table1.KeyID = Table2.KeyID

--
David Portas
SQL Server MVP
--

Steven Wilmot
5/13/2004 5:57:34 PM

[quoted text, click to view]

left outer join

(or just left join)

AddThis Social Bookmark Button