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

Need help with a self join problem - PervasiveSQL

Status
Not open for further replies.

dison123

Programmer
Feb 29, 2008
5
0
0
GB
Hello I am trying create a series of views to show details of staff and their linemanagers,yet can not get them to work. Details of Staff records are in 2 files (Staff1,Staff2), They are linked via fieldname 'PersonKey' and Staff2 contains a field 'PersonKeyMainline' which is the personkey for the linemanager. I am trying to pull out details for both the Staff member and the line manager.

this is my attempt...

SELECT
Staff1.FirstName,
Staff1.Surname,
Staff2.PersonKey,
Staff2.Address1,
Staff2.Address2,
Staff2.Address3,
Staff2.Postcode,
Staff2.PersonKeyMainline

From Staff2 Child2,staff1 Child,Staff1 Parent,Staff2 Parent2
Where Child.PersonKey = Child2.PersonKey AND Child2.PersonKeyMainline = Parent2.PersonKeyMainline and Parent.PersonKeyMainline = Parent.Personkey

I cannot get this to work. I have only just started to learn SQL so have probably made some fundamental errors.

Thankyou in advance.

David Ison
 
What's the behavior are you seeing?
Also, what version of PSQL are you using?


Mirtheil
Certified Pervasive Developer
Certified Pervasive Technician
 
Thanks for the speedy response.

I am Using pervasive SQL version 9.50.077.002.
When trying to execute the script I get
"[LNA][Pervasive][ODBC Engine Interface]Error in expression: Staff1 . FirstName
 
I think it's because you don't have a reference to Staff1 other than to alias it. You might try:
SELECT
Parent.FirstName,
Parent.Surname,
Parent2.PersonKey,
Parent2.Address1,
Parent2.Address2,
Parent2.Address3,
Parent2.Postcode,
Parent2.PersonKeyMainline

From Staff2 Child2,staff1 Child,Staff1 Parent,Staff2 Parent2
Where Child.PersonKey = Child2.PersonKey AND Child2.PersonKeyMainline = Parent2.PersonKeyMainline and Parent.PersonKeyMainline = Parent.Personkey

Mirtheil
Certified Pervasive Developer
Certified Pervasive Technician
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top