Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Can not get this right
Message
From
27/05/2008 03:03:34
 
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Environment versions
Visual FoxPro:
VFP 9 SP2
OS:
Windows XP
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01319440
Message ID:
01319604
Views:
16
This message has been marked as a message which has helped to the initial question of the thread.
>>Hi Naomi, relax your brain ...
>>try:
>>
>>SELECT People.cID,;
>>       People.LName,;
>>       People.FName,;
>>       Home.Phone   AS Home,;
>>       Office.Phone AS Office,;
>>       Cell.Phone   AS Cell,;
>>....
>>FROM People;
>>LEFT JOIN Phones Home ON People.cId == Home.cId AND Home.Type =='Home';
>>LEFT JOIN Phones Office ON People.cId == Home.cId AND Office.Type =='Office';
>>LEFT JOIN Phones Cell ON People.cId == Home.cId AND Cell.Type =='Cell'  ;
>>....
>>
>
>I believe I tried this variation too and it didn't work as I wanted it to.
>
>What would you get if you have, say, 2 home phones and 1 cell and no e-mail, for example?


You are right, design is not enough, Phones table needs a Row column that correlate the phones types.
SET NULLDISPLAY TO ''

CREATE CURSOR People (cID INT,LName VARCHAR(20),FName VARCHAR(30))
INSERT INTO People VALUES (1,'Naomi','Nosonovsky')

CREATE CURSOR Phones (cID INT,row INT,Type CHAR(10),Phone VARCHAR(30))
INSERT INTO Phones VALUES (1,1,'Home','HOMETEL 1')
INSERT INTO Phones VALUES (1,2,'Home','HOMETEL 2')
INSERT INTO Phones VALUES (1,1,'Cell','CELLULAR 1')
INSERT INTO Phones VALUES (1,2,'Cell','CELLULAR 2')
INSERT INTO Phones VALUES (1,3,'Cell','CELLULAR 3')
INSERT INTO Phones VALUES (1,4,'Office','OFFICE 4')
INSERT INTO Phones VALUES (1,2,'Office','OFFICE 2')


SELECT	;
	People.cID ;
,	People.LName	;
,	People.FName	;
,	NVL(Home.row,NVL(Cell.row,Office.row)) Row;
,	Home.Phone		Home	;
,	Cell.Phone		Cell	;
,	Office.Phone	Office	;
	FROM 		(SELECT * FROM Phones WHERE Type	='Home')	Home ;
	FULL JOIN	(SELECT * FROM Phones WHERE Type	='Cell')	Cell	ON Home.cId = Cell.cId AND Home.row = Cell.row ;
	FULL JOIN	(SELECT * FROM Phones WHERE Type	='Office')	Office	ON Home.cId = Office.cId AND Home.row = Office.row	;
		 JOIN	People ON People.cID = NVL(Home.cId,NVL(Cell.cId,Office.cId));
	ORDER BY 1 , 4
don't forget to add optimization index, otherwise ...
Previous
Reply
Map
View

Click here to load this message in the networking platform