Table Joining
Posted: Wed Feb 02, 2011 5:02 pm
I'm trying to get my head wrapped around table joining. What I have so far is as follows:
[text]<customer_accounts>
customer_id first_name last_name
<employee_accounts>
employee_id username password
<project1>
project1_id customer_id employee_id
<project2>
project2_id customer_id employee_id[/text]
What I want to do is query the database to show me the first and last name of the customer who has a project with employee X. So maybe one customer works with employee 1 on project1, but not project2. Maybe another customer works with employee 1 on project2, but not project1. So on and so forth...
I've tried the following, but
I'm feeling I'm way off target on my attempt, so please go easy on me 
Thanks in advance!
[text]<customer_accounts>
customer_id first_name last_name
<employee_accounts>
employee_id username password
<project1>
project1_id customer_id employee_id
<project2>
project2_id customer_id employee_id[/text]
What I want to do is query the database to show me the first and last name of the customer who has a project with employee X. So maybe one customer works with employee 1 on project1, but not project2. Maybe another customer works with employee 1 on project2, but not project1. So on and so forth...
I've tried the following, but
Code: Select all
SELECT customer_accounts.first_name,customer_accounts.last_name
FROM customer_accounts,project1,project2
WHERE project1.employee_id=1 AND project2.employee_id=1 AND customer_accounts.customer_id=project1.customer_idThanks in advance!