Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Questoin about SELECT
Message
From
12/09/2001 02:30:43
 
 
To
11/09/2001 10:03:51
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00555024
Message ID:
00555391
Views:
20
This message has been marked as the solution to the initial question of the thread.
Hi!

Yes, it will restrict the result. Just a simple sample:
create cursor SomeAlias (fInteger I, fCharacter C(30), ttt I, ttt2 I )
insert into SomeAlias (fInteger,fCharacter ) values (1,"11")
insert into SomeAlias (fInteger,fCharacter ) values (2,"22")
insert into SomeAlias (fInteger,fCharacter ) values (3,"33")
insert into SomeAlias (fInteger,fCharacter ) values (4,"44")

create cursor SomeAlias2 (fInteger I, fInteger2 I, fCharacter2 C(30))
insert into SomeAlias2 (fInteger, fInteger2,fCharacter2 ) values (1,12,"112")
insert into SomeAlias2 (fInteger, fInteger2,fCharacter2 ) values (2,22,"222")
insert into SomeAlias2 (fInteger, fInteger2,fCharacter2 ) values (3,32,"332")
insert into SomeAlias2 (fInteger, fInteger2,fCharacter2 ) values (4,42,"442")

create cursor SomeAlias3 (fInteger3 I, fInteger2 I, fCharacter3 C(30))
insert into SomeAlias3 (fInteger3, fInteger2,fCharacter3 ) values (13,12,"113")
insert into SomeAlias3 (fInteger3, fInteger2,fCharacter3 ) values (23,22,"223")
insert into SomeAlias3 (fInteger3, fInteger2,fCharacter3 ) values (33,32,"333")
insert into SomeAlias3 (fInteger3, fInteger2,fCharacter3 ) values (43,42,"443")

create cursor SomeAlias4 (fInteger3 I, fInteger4 I, fCharacter4 C(30))
insert into SomeAlias4 (fInteger3, fInteger4,fCharacter4 ) values (13,14,"114")
insert into SomeAlias4 (fInteger3, fInteger4,fCharacter4 ) values (23,24,"224")
insert into SomeAlias4 (fInteger3, fInteger4,fCharacter4 ) values (33,34,"334")
insert into SomeAlias4 (fInteger3, fInteger4,fCharacter4 ) values (43,44,"444")


SELECT SomeAlias.*, SomeAlias2.fInteger2, SomeAlias2.fCharacter2, ;
	SomeAlias3.fInteger3, SomeAlias3.fCharacter3, ;
	SomeAlias4.fInteger4, SomeAlias4.fCharacter4 ;
	FROM SomeAlias;
		INNER JOIN SomeAlias2 ;
			ON SomeAlias.fInteger = SomeAlias2.fInteger;
		LEFT OUTER JOIN SomeAlias3;
			ON SomeAlias2.fInteger2 = SomeAlias3.fInteger2 ;
		INNER JOIN SomeAlias4  ;
			ON SomeAlias3.fInteger3 = SomeAlias4.fInteger3 ;
	WHERE SomeAlias4.fInteger4<44 ;
	INTO CURSOR Results
In the query I restrict to get only first 3 records from the 4-th table. Result of query is 3 records.

>Vlad
>
>I'm well aware that I can achieve my results by using the LEFT join, but is a SELECT supposed to work in this way, is an INNER JOIN between 2 tables supposed to affect the selection from the 1st Table which is not "directly" JOINED?
>
>Kev
>>Hi!
>>
>>That is why I said to LEFT JOIN the RESOURCE table. INNER JOINED with ALLOCATION should return no record, right? But for main result you still want a record from the with all nulls to get a main records, right?
>>
>>When you left join ALLOCATION, then left join RESOURCE, it will work correctly, but you will get the record from ALLOCATION and no record from RESOURCE (all nulls). Does this matter? Usually not, however, if yes (you already built interface that cannot work when allocation record is correct and no resource), you can use expression for getting fields from ALLOCATION, somethign like following:
>>
>>SELECT ...., iif(RESOURCE.ID IS NULL,NULL,ALLOCATION.NAME) as Allocation_Name, ...
>>
>>This way you will reach it.
>>
>>
>>>>Hi!
>>>>
>>>>What you meant? Sorry, I still bad in English and do not know meaning of many standard phrases.
>>>
>>>I meant that your response was a quick and simple one without answering my question.
>>>
>>>>
>>>>Really, the result might be not what you want. For example, when you have no record in Allocation and record in Resource, you will not get that record. This is because Resource linked to the Allocation only, so it is depended on it. When you want to retrieve Resource when no allocation, you require to left join Resource table to Client or Referral.
>>>
>>>Well, basically I want the ALLOCATION and RESOURCE records INNER JOINED (RESOURCE is only related to ALLOCATION) so that even if there isn't an ALLOCATION, it will return a row. But if there is no RESOURCE, but there IS an ALLOCATION record, then I still want it to display. But if I INNER JOIN the 2, then it stops the whole row from returning - this I don't think is right (or it's just a pain and I'll have to PUWI!) because I'm not INNER JOINING the RESOURCE to REFERRAL, I'm INNER JOINING RESOURCE to ALLOCATION, which is LEFT OUTER JOINING to REFERRAL - do you know what I mean?
>>>
>>>Kev
>>>
>>>
>>>
>>>>
>>>>>Vlad
>>>>>
>>>>>That's a response that favours you greatly :)
>>>>>
>>>>>I take it you'd rather not go into it?
>>>>>
>>>>>Kev
>>>>>>Hi!
>>>>>>
>>>>>>Just LEFT JOIN the Resource table ;)))
>>>>>>
>>>>>>>Hi
>>>>>>>
>>>>>>>I have the following Select:
>>>>>>>
>>>>>>>
>>>>>>>SELECT Referral.*;
>>>>>>>  FROM Referral;
>>>>>>> INNER JOIN Client;
>>>>>>>    ON Referral.Cl_Ref = Client.Cl_Ref;
>>>>>>>  LEFT OUTER JOIN Allocation;
>>>>>>>    ON Client.Cl_Ref = Allocation.Cl_Ref;
>>>>>>> INNER JOIN Resource;
>>>>>>>    ON Allocation.Rs_Ref = Resource.Rs_Ref;
>>>>>>> WHERE BETWEEN(Referral.Re_Date, ldStartDate, ldEndDate);
>>>>>>>  INTO CURSOR Results
>>>>>>>
>>>>>>>
>>>>>>>Now, my question is : Will the 2nd Inner Join restrict the results if there is no RESOURCE record relating to the ALLOCATION record. What I want to is for it to still retrieve the REFERRAL records, even if there is no related record between RESOURCE & ALLOCATION, because I'm only LEFT Joining the ALLOCATION.
>>>>>>>
>>>>>>>The solution is simple, change the INNER to a LEFT OUTER, so basically, I'm just confirming what my thoughts are.
>>>>>>>
>>>>>>>Any ideas?
>>>>>>>Thanks
>>>>>>>Kev
Vlad Grynchyshyn, Project Manager, MCP
vgryn@yahoo.com
ICQ #10709245
The professional level of programmer could be determined by level of stupidity of his/her bugs

It is not appropriate to say that question is "foolish". There could be only foolish answers. Everybody passed period of time when knows nothing about something.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform