Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Complicated tree query
Message
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Environment versions
Visual FoxPro:
VFP 9 SP1
OS:
Windows XP SP2
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01160753
Message ID:
01161109
Views:
19
>>>Hi, Edgar!
>>>
>>>First of all, try to avoid using the reserved words as the field names
>>>
>>>
>>>USE your_table_name IN 0 ALIAS PARENTS
>>>USE your_table_name AGAIN IN 0 ALIAS CHILDS
>>>* select all childs from top record
>>>GO TOP
>>>SELECT Tname FROM CHILDS INTO CURSOR cRelations WHERE childs.pid=parents.id
>>>BROWSE nowait
>>>
>>
>>There is no need to open table twice, you could self-join the table:
>>
>>SELECT ....;
>>    FROM TableName Master;
>>JOIN TableName Child ON childs.pid=parents.id;
>>INTO CURSOR crsTest
>>
>
>Hi, Borislav!
>Yes, we can use and self-join, but your syntax must be changed
>when we want to select just one field
>otherwise you will get an error about non-unique field name.
>And question was about selection one field under specific condition,
>so I think that using one table under two different aliases
>is more simple.
>WBR,
>Juri

No problems at all when you want to select as many fields as you want, you just must put alias before them:
SELECT Master.Field1, Master.Field2, Child.*;
    FROM TableName Master;
JOIN TableName Child ON childs.pid=parents.id;
WHERE Master.Field3 = something;
INTO CURSOR crsTest

*** or for one field:
SELECT Master.Field1;
    FROM TableName Master;
JOIN TableName Child ON childs.pid=parents.id;
WHERE Master.Field3 = something;
INTO CURSOR crsTest
Against Stupidity the Gods themselves Contend in Vain - Johann Christoph Friedrich von Schiller
The only thing normal about database guys is their tables.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform