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

PLEASE HELP

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0

select LEFT(Fedid, 11), LEFT(vitalpayor, 7), LEFT(ghino, 11) from (sitedbf),
Payoracrdbf, Institutdbf where left(CLASS,2) = left(exppayor,2)

why is this statement incorrect??, all of these are tables (sitedbf),Payoracrdbf, Institutdbf

im getting some result, but not everything??? would it be my foreign keys??? please help
 
In general if you want to join three tables you need two conditions on keys.

Code:
SELECT t1.*, t2.*, t3.*
FROM t1, t2, t3
WHERE t1.id = t2.id
  AND t2.id = t3.id

or
Code:
SELECT t1.*, t2.*, t3.*
FROM t1, t2, t3
WHERE t1.id = t2.id
  AND t1.id = t3.id

You may be losing rows because some values of left(CLASS,2) have no matching values of left(exppayor,2). That is corrected by an outer join.
Code:
SELECT t1.*, t2.*, t3.*
FROM t1, t2, t3
WHERE t1.id = t2.id
  AND t2.id *= t3.id

which is the same as
Code:
SELECT t1.*, t2.*, t3.*
FROM t1
  JOIN t2 ON t1.id = t2.id
  LEFT JOIN t3 ON t2.id = t3.id


It is better practice to qualify column names with their table names when selecting from more than one table. This helps the SQL processor, it helps you when you look at the query next month, it helps the next programmer, and it helps us understand your problem.

In this case we need to know which tables CLASS and exppayor belong to.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top