Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL JOIN STATEMENT

Status
Not open for further replies.

needmoremoney

Technical User
Mar 30, 2005
123
US
Hello all,

I have three tables, that I would like to join together.
This is my statement for two tables, how do I modified it to work with three table?

My third table is called EAccr
it have multiple fields but I only want the id and begin date fields. The fields are EAccr.id and EAccr.begindate.

.........
SELECT EInfo.id, EInfo.lastName, EInfo.firstName,
EInfo.middleName, EDed.dcode, CDed.description,
EDed.lastDate, EDed.rate, EDed.paidTowardsGoal, EDed.goal
INTO tempAccrualGoals
FROM (EInfo INNER JOIN EDed ON EInfo.id = EDed.id)
INNER JOIN CDed ON EDed.dcode = CDed.dcode
WHERE EDed.goal>0;
.......

Any help.. thanks much..
 
Assuming the EAccr table has a foreign key that relates to the EInfo table
Code:
SELECT EInfo.id, EInfo.lastName, EInfo.firstName,
    EInfo.middleName, EDed.dcode, CDed.description,
    EDed.lastDate, EDed.rate, EDed.paidTowardsGoal, EDed.goal,
    EAccr.id,
    EAccr.begindate
INTO tempAccrualGoals
FROM EInfo
INNER JOIN EDed ON EInfo.id = EDed.id
INNER JOIN CDed ON EDed.dcode = CDed.dcode
JOIN EAccr ON EInfo.id = EAccr.id
WHERE EDed.goal > 0

 
hmm doesn't seem to be working..

Any other suggestions.. the join is correct though. Do you think my ( ) might need to be modified.
 
the parens in the JOIN ARE extraneous, leave them out, they neither harm nor help. they just confuse people.

"doesn't seem to be working" covers a lot of territory. What do you mean, zero rows, duplicate rows, something else?
 
ooops sorry for unclear statement. Here's the fun thing about this.. I don't remember the error but it had something to do with the last few lines..

I figured it out. i don't even need the third table, the field that I needed was in the second table already. I just added a few more fields to the original statement and it works fine now.

still though, I'm curious about inner joining three tables though:

I would assume that this is the process:
...
INNER JOIN EDed ON EInfo.id = EDed.id
INNER JOIN EDed ON EInfo.id = EAccr.id
INNER JOIN EDed ON EInfo.id = CDed.id
...

Something like the above i think.

Thanks rac2, for you inputs.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top