Friday, February 17, 2012

Data from Three Tables

I have three tables: Contact, Staff, Codes.
My SQL statement is as follows:
SELECT tm5user.contact.full_name, tm5user.contact.phone1,
tm5user.contact.firm, tm5user.contact.city, tm5user.staff.[last],
tm5user.staff.[first],
tm5user.codes.[desc]
FROM tm5user.contact INNER JOIN
tm5user.staff ON tm5user.contact.staff =
tm5user.staff.init INNER JOIN
tm5user.codes ON tm5user.contact.ccode =
tm5user.codes.ccode
The problem is that for each contact record, I get between 1 and 5 records
in my result set. I would like only one record displayed for each contact
record.
How can I do this, I am at a loss.
Please help.
Thanks,
GaryYour Joins are incomplete, means that some key columns are missing, but
impossible for us to solve the problem without knowing the DDL. Post it here
and we could might help you.
The table have a onetomany or manytomany relationsship to each other, but
guessing wont help you further, so try to post the ddl.
HTH, Jens Smeyer.
"Gary Paris" <yada@.somewhereovertherainbow.com> schrieb im Newsbeitrag
news:e2632a7PFHA.1932@.tk2msftngp13.phx.gbl...
>I have three tables: Contact, Staff, Codes.
>
> My SQL statement is as follows:
> SELECT tm5user.contact.full_name, tm5user.contact.phone1,
> tm5user.contact.firm, tm5user.contact.city, tm5user.staff.[last],
> tm5user.staff.[first],
> tm5user.codes.[desc]
> FROM tm5user.contact INNER JOIN
> tm5user.staff ON tm5user.contact.staff =
> tm5user.staff.init INNER JOIN
> tm5user.codes ON tm5user.contact.ccode =
> tm5user.codes.ccode
> The problem is that for each contact record, I get between 1 and 5 records
> in my result set. I would like only one record displayed for each contact
> record.
> How can I do this, I am at a loss.
> Please help.
> Thanks,
> Gary
>|||I was playing around in Enterprise manager and found that in the Codes
table, there were many codes that were the same, but another field called
rec_type was unique. By putting in a where clause, that solved the problem.
Thank you,
Gary
"Jens Smeyer" <Jens@.sqlserver2005.de> wrote in message
news:eZTSGe7PFHA.2520@.tk2msftngp13.phx.gbl...
> Your Joins are incomplete, means that some key columns are missing, but
> impossible for us to solve the problem without knowing the DDL. Post it
> here and we could might help you.
> The table have a onetomany or manytomany relationsship to each other, but
> guessing wont help you further, so try to post the ddl.
>
> HTH, Jens Smeyer.
>
> "Gary Paris" <yada@.somewhereovertherainbow.com> schrieb im Newsbeitrag
> news:e2632a7PFHA.1932@.tk2msftngp13.phx.gbl...
>

No comments:

Post a Comment