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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

inner join sql question STILL NOT SOLVED!

Status
Not open for further replies.

Smarty

Programmer
Apr 12, 2001
191
BE
I have a sql question. I want a query which uses 3 tables: CONTACTS, TASKS and TASKTYPES.

Each contact can have several tasks, so i think there needs to be an inner join between contacts and tasks on the field ID_Contact (that is not the problem).

There is in the table tasks a field (ID_TASKTYPE) which needs to be replaced by the [TASKTYPES].[TAKSTYPE] field of the tasktypes table whith the corresponding ID_TASKTYPE. How do i do this? Subselect or where clause?

the query should look like this:

CONTACT 1
=> Taks 1 for contact 1 with the ID_tasktype changed by the tasktype from the table TASKTYPES
=> Taks 2 for contact 1
...

CONTACT 2
...


It gets even more complicated... on the CONTACT table there is an ID_COMPANY and i have to look up the companyname in the table COMPANIES like i have to do with the tasktypes...

Hmmz... i guess this isn't so easy huh

 
This is actually an easy exercise in SQL Join queries. That is, it is easy if I correctly understand the requirement and description. Here is a proposed query. Use it as a model for your own.

Select
a.ID_Contact,
a.ContactName,
c.ID_TaskType,
c.TaskType,
d.ID_Company,
d.CompanyName

From Contacts As a
Inner Join Tasks As b
On a.ID_Contact=bID_Contact
Inner Join TASKTYPES As c
On b.ID_TaskType=c.ID_TaskType
Inner Join Company As d
On a.ID_Company=d.ID_Company Terry

"I'm not dumb. I just have a command of thoroughly useless information." - Calvin, of Calvin and Hobbes
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top