dbTalk Databases Forums  

JOINing detail tables into the main table

comp.databases.ms-access comp.databases.ms-access


Discuss JOINing detail tables into the main table in the comp.databases.ms-access forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
rettigcd@bigfoot.com
 
Posts: n/a

Default JOINing detail tables into the main table - 12-16-2004 , 03:41 PM






I have 2 tables:

person (person_id, first_name, last_name)
phone(phone_id, person_id, number, type)

Each person may have many phone numbers, one for each type
(home,work,cell)

I am trying to create a query that lists every person and their
home-phone number if they have one.

The problem arises when somebody has a work phone but no home phone. I
can't seem to filter out the work phone and still get the person's
name.

I tried this:

SELECT person.*,phone.* FROM person
LEFT JOIN phone
ON person.person_id = phone.person_id AND phone.type='home';

but got an "join expression not supported" on the (phone.type='home')
part.

I tried moving the phone.type into the WHERE clause but that doesn't
work because it removes people that have other phones but no home
phones.

I've done this before but now I can't seem to get it to work
Any help is appreciated.

thanks,
Dean


Reply With Quote
  #2  
Old   
Tony D'Ambra
 
Posts: n/a

Default Re: JOINing detail tables into the main table - 12-16-2004 , 04:23 PM







SELECT person.*, phone.number
FROM person LEFT JOIN ON person.person_id = phone.person_id
WHERE (((phone.type)='home'));


--

Tony D'Ambra
Web Site: aadconsulting.com
Web Blog: accessextra.net



<rettigcd (AT) bigfoot (DOT) com> wrote

Quote:
I have 2 tables:

person (person_id, first_name, last_name)
phone(phone_id, person_id, number, type)

Each person may have many phone numbers, one for each type
(home,work,cell)

I am trying to create a query that lists every person and their
home-phone number if they have one.

The problem arises when somebody has a work phone but no home phone. I
can't seem to filter out the work phone and still get the person's
name.

I tried this:

SELECT person.*,phone.* FROM person
LEFT JOIN phone
ON person.person_id = phone.person_id AND phone.type='home';

but got an "join expression not supported" on the (phone.type='home')
part.

I tried moving the phone.type into the WHERE clause but that doesn't
work because it removes people that have other phones but no home
phones.

I've done this before but now I can't seem to get it to work
Any help is appreciated.

thanks,
Dean




Reply With Quote
  #3  
Old   
rettigcd@bigfoot.com
 
Posts: n/a

Default Re: JOINing detail tables into the main table - 12-17-2004 , 08:32 AM



Tony - thanks for the input but that doesn't work either. That doesn't
show anybody unless they have a home phone. I want the people to show
up even if they don't have a home phone.

I did get it to work by placing () around my ON clause.

ON ((person.person_id = phone.person_id) AND (phone.type='home'))

The reason it quit working was that Access Design View decided to
remove the outter parenthesis without telling me. I wish I could
figure out how to turn that "feature" off.

Well as long as I don't edit the SQL statement everything seems to stay
as is.

-Dean


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.