Select Statement
Posted in 1999
Topics: SQL Development & Query Writing, Data Types & Schema Design
I have 2 tables -- what is the best way to pull data for 2 different number fields that both relate only to one character field? Example: Table 1 contains Initiator(number) Referred To(number) 3 4 4 6 Table 2 contains Group Name(varchar) Group Number(number) Accounting 3 Billing 4 Sales 6 I want to select the data for the "initiators" and the "referred to" but use the character field names, not the numbers.... Sorry for the "not so intelligent question", but I am a real "newbie" to SQL, Informix, etc.
In article <81tceg$cqe$1@bgtnsc03.worldnet.att.net>,
"Boscia" <rwboscia@worldnet.att.net> wrote:
> I have 2 tables -- what is the best way to pull data for 2 different
number
> fields that both relate only to one character field?
>
> Example: Table 1 contains
>
> Initiator(number) Referred To(number)
>
> 3 4
> 4 6
>
> Table 2 contains
>
> Group Name(varchar) Group Number(number)
> Accounting 3
> Billing 4
> Sales 6
>
> I want to select the data for the "initiators" and the "referred to"
but use
> the character field names, not the numbers....
>
> Sorry for the "not so intelligent question", but I am a real "newbie"
to
> SQL, Informix, etc.
OK, here 'tis:
SELECT i.GroupName, r.GroupName
FROM table1 l, table2 i, table2 r
WHERE l.initiator = i.GroupNumber
AND l.refferedto = r.GroupNumber;
Usually SQL flows from a user's description of what is desired, because
SQL is a USER language NOT a PROGRAMMER language. A user might has
asked: For each referral in table one show the GroupNames of both the
initiator group-id and the referred-to group-id. This more easily
points to the required joins.
Art S. Kagel
Sent via Deja.com http://www.deja.com/
Before you buy.
In article <81tceg$cqe$1@bgtnsc03.worldnet.att.net>,
"Boscia" <rwboscia@worldnet.att.net> wrote:
> I have 2 tables -- what is the best way to pull data for 2 different
number
> fields that both relate only to one character field?
>
> Example: Table 1 contains
>
> Initiator(number) Referred To(number)
>
> 3 4
> 4 6
>
> Table 2 contains
>
> Group Name(varchar) Group Number(number)
> Accounting 3
> Billing 4
> Sales 6
>
> I want to select the data for the "initiators" and the "referred to"
but use
> the character field names, not the numbers....
>
> Sorry for the "not so intelligent question", but I am a real "newbie"
to
> SQL, Informix, etc.
OK, here 'tis:
SELECT i.GroupName, r.GroupName
FROM table1 l, table2 i, table2 r
WHERE l.initiator = i.GroupNumber
AND l.refferedto = r.GroupNumber;
Usually SQL flows from a user's description of what is desired, because
SQL is a USER language NOT a PROGRAMMER language. A user might has
asked: For each referral in table one show the GroupNames of both the
initiator group-id and the referred-to group-id. This more easily
points to the required joins.
Art S. Kagel
Sent via Deja.com http://www.deja.com/
Before you buy.