473,385 Members | 1,707 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

JOINing detail tables into the main table

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

Nov 13 '05 #1
2 1117

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

<re******@bigfoot.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
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

Nov 13 '05 #2
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

Nov 13 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Job Lot | last post by:
Is there anyway of Joining two or more DataTable with similar structure? I have three DataTables with following structures Data, AmountB/F, Repayments, InterestCharged and AmountC/F i want...
2
by: James | last post by:
Can anyone please shed some light on the following... I have a framework that uses dynamically created tables, named using an incremental "attribute set ID", as follows: attrdata_1 attrdata_2...
3
by: james | last post by:
Hi, I would like to get all the records from 9 tables that have the same field value in one field (it is a unique field)that is shared by all the tables. Would this method of joining work: ...
3
by: Andrew | last post by:
Here's my problem: I built a system for data entry and export based on a schema given to my by the state. The output of the data is fixed-width, and a good number of the fields in each row...
1
by: krzys | last post by:
here is the following situation : I have a dataset with two tables this.daCustomers.Fill(dsData1, "Customers"); this.daOrders.Fill(dsData1, "Orders"); as You see there are tables from...
2
by: Thomas R. Hummel | last post by:
Hello, I am currently working on a monthly load process with a datamart. I originally designed the tables in a normalized fashion with the idea that I would denormalize as needed once I got an...
4
by: Rnt6872 | last post by:
Table A Table B BOL# B_BOL# Chargeback# Hi All, I have been struggling with this for...
2
by: John | last post by:
Hi I am trying to create a master/detail form. I have my master and details tables dragged onto the dataset. I have also dragged the fields from master table on the form which has created the...
2
by: Neekos | last post by:
Im working on web tool that will allow supervisors to see a list of their agents and their call stats for a call center. I have one main table that holds employee IDs and their supervisor names....
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.