Board index » delphi » Join two ID Fields With One Source

Join two ID Fields With One Source

Suppose I have a table like this:
Customer_Name, SalesMan_ID, Mechanic_ID

The two ID fields are different, but both can be used to look up a name in a
master table. How can I wrote an SQL statement to look up the name for both
of these IDs?

Thanks!

--
Jim Carr

 

Re:Join two ID Fields With One Source


On Thu, 29 Jul 1999 12:45:55 -0700, "Jim Carr" <jc...@omegalegal.com>
wrote:

Quote
>Suppose I have a table like this:
>Customer_Name, SalesMan_ID, Mechanic_ID

>The two ID fields are different, but both can be used to look up a name in a
>master table. How can I wrote an SQL statement to look up the name for both
>of these IDs?

What is the database type? Not sure if all database back-end systems
support this, but the BDE's implementation of SQL allows you to join tables
bases on concatenated values. For example:

  SELECT *
  FROM Table1 T1
    JOIN Table2 T2
      ON (T1.ID = T2.IDa || T2.IDb)

But your description does not really sound like you are trying to join
tables (as implied in the subject field). Instead, it looks like you simply
wish to filter a query result set using comparison values for two fields.
That is easy to do. Simply supply two logical conditions in the statement's
WHERE clause connected by the AND operator. For example:

  SELECT Customer_Name
  FROM YourTable
  WHERE (SalesMan_ID = "100") AND
    (Mechanic_ID = "29")

_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
Steve Koterski         "Television is a medium because anything well done
Felton, CA             is rare."
                                                 -- Fred Allen (1894-1956)

Other Threads