Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
SQL Problem in 3 files
Message
De
24/07/1997 12:54:01
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
 
À
24/07/1997 02:38:23
Vinod Parwani
United Creations L.L.C.
Ad-Dulayl, Jordanie
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00041299
Message ID:
00041493
Vues:
71
>>>Select name.Name, Contact.phone, address.address ;
>>> from name, contact, address ;
>>> where name.code=contact.code and contact.code=address.code group by name.code
>>>
>>>but it is giving me one record only...
Hi Vinod,
I think I'm confused with table links. Here is why I understand :
Name table Contact table
Name1, code1 -----+--->code1, contact1
Name2, code2 --+ +--->code1, contact2
Name3, code3 | +---------------------+----code1, adrress1
+ +---->code2, contact21 +----code1, adrress2
| +---->code2, contact22
| +----code2, adrress21
| +----code2, address22
+-->code3, contact31
Name4, code4
If this is true then above SQL would return :
name1, contact2, adress2
name2, contact22, adress22
Because you want records that code exists in all 3 tables and grouping by name. You miss records (name3, contact31, name4) for their code don't exist in all 3 tables. Without grouping you would get :
name1, contact1, address1
name1, contact1, address2
name1, contact2, address1
name1, contact2, address2
name2, contact21, address21
name2, contact21, address22
name2, contact22, address21
name2, contact22, address22

If you want all names you could use :
select name, contact, adres from name a left join contact b on a.code=b.code left join address c on a.code=c.code

Except above this would give all the names. But I think none is what you want. You want :
Name1, contact1, address1
Name1, contact2, address2
Name2, contact21, address21
Name2, contact22, address22 and maybe other names that doesn't have any contacts or addresses. Right ? If so as far as I know there is no way of doing this with SQL unless you also have another key linking to address table. SQL will always end you with contactreccount*addressreccount for matching series. To establish it you should create a cursor and fill it with a routine.
use names in 0 order tag name
use contacts in 0 order tag code
use address in 0 order tag code
select names
set relation to code into contacts, code into address
create cursor SQLcursor (name c(10), phone c(10), address c(10))
select names
scan while !eof("names")
m.name = names.name
do while !eof("contacts") or !eof("address")
m.phone = contacts.phone
m.address = address.address
insert into SQLcursor from memvar
if !eof("contacts")
skip in "contacts"
endif
if !eof("address")
skip in "address"
endif
enddo
endscan
But I still wonder if these addresses belong to contacts then you should be relying on entry order to match them.
Best regards
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform