Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Another SQL Question
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
01031642
Message ID:
01031690
Vues:
11
This test gives me exact 3 records:
CREATE CURSOR Contacts (RecordId C(10), FName C(40), LName C(40))
CREATE CURSOR Links    (RecordId C(10), ParentId C(10), DataId C(10), Key C(10))
CREATE CURSOR Phones   (RecordId C(10), Caption C(40), Phone C(20), Last L)

INSERT INTO Contacts VALUES ("0000000001", "John", "Smith")

INSERT INTO Links VALUES ("AAAAAAAAAA","0000000001", "ZZZZZZZZZZ", "Phone")
INSERT INTO Links VALUES ("AAAAAAAAAA","0000000001", "QQQQQQQQQQ", "Phone")
INSERT INTO Links VALUES ("AAAAAAAAAA","0000000001", "FFFFFFFFFF", "Phone")

INSERT INTO Phones VALUES ("ZZZZZZZZZZ","Home","1234567890", .t.)
INSERT INTO Phones VALUES ("QQQQQQQQQQ","bUSINESS","222234567890", .t.)
INSERT INTO Phones VALUES ("FFFFFFFFFF","Small","21231321", .t.)

SELECT Contacts.*, Phones.*;
       FROM Links;
       LEFT JOIN Contacts ON Links.ParentId = Contacts.RecordId;
       LEFT JOIN Phones   ON Links.DataId   = Phones.RecordId;
INTO CURSOR cAllPhones

BROW
>Close. The phone records appear as separate record before
>the contact records.
>
>>
>>SELECT Contacts.*, Phones.*;
>>       FROM Links;
>>       LEFT JOIN Contacts ON Links.ParentId = Contacts.RecordId;
>>       LEFT JOIN Phones   ON Links.DataId   = Phones.RecordId;
>>INTO CURSOR cAllPhones
>>
>>Is that what you need?
>>
>>
>>>I have a Contacts table. I also have a Phones table. They are related
>>>through a Links table. I would like to pull the client record, and have
>>>all the phone numbers on the client record.
>>>
>>>Anyone?
>>>
>>>
>>>The relationships:
>>>
>>>Contacts
>>>   |
>>>   -< Links
>>>       |
>>>       -< Phones
>>>
>>>
>>>
>>>The structures:
>>>
>>>Contacts
>>>RecordId  FName   LName
>>>-----------------------------------------------------
>>>00000001  Joe     Smith
>>>
>>>Links
>>>RecordId  ParentId  DataId    Key
>>>-----------------------------------------------------
>>>AAAAAAAA  00000001  ZZZZZZZZ  "phone"
>>>AAAAAAAA  00000001  QQQQQQQQ  "phone"
>>>AAAAAAAA  00000001  FFFFFFFF  "phone"
>>>
>>>
>>>Phones
>>>RecordId  Caption         Phone       Last
>>>-----------------------------------------------------
>>>ZZZZZZZZ  Home            8005551212  .T.
>>>QQQQQQQQ  Business        8001212555  .T.
>>>FFFFFFFF  Cell            8885544877  .T.
>>>
Against Stupidity the Gods themselves Contend in Vain - Johann Christoph Friedrich von Schiller
The only thing normal about database guys is their tables.
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform