Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
LEFT JOIN IN SQL for FPD 2.6
Message
 
To
19/02/2000 04:20:04
General information
Forum:
Visual FoxPro
Category:
FoxPro 2.x
Miscellaneous
Thread ID:
00334439
Message ID:
00334450
Views:
40
Hi Zlatko.

Try this:
* set up some test data
create cursor First_Table (PK N(4,0), DataValue C(10))
insert into First_Table values (1, "One")
insert into First_Table values (2, "Two")
insert into First_Table values (3, "Three")
insert into First_Table values (4, "Four")
insert into First_Table values (5, "Five")

create cursor second_Table (PK N(4,0), FK N(4,0), DataValue C(10))
insert into Second_Table Values (1, 1, "First")
insert into Second_Table Values (2, 2, "Second")
insert into Second_Table Values (3, 3, "Third")

* Select all the records from the first table and any matching from the second

select F.*, s.* ;
	from First_Table F, Second_Table s ;
	where f.pk = s.fk ;
UNION ;
select f.*, 0000, 0000, space(10) ;
	from First_Table F ;
	where f.pk not in (select s.fk from Second_Table s) ;
INTO CURSOR LJoin

brow
The key is the UNION - get all of the records that do match from the first table, and UNION that set with all of the records that don't match.

HTH

Cheers,

Andrew

>FP 2.6, DOS. I've got two tables and connect them with a SQL statement using »WHEN first.key = second.key«. It works fine until in the second table doesn't exist a related record. In that case the record
>from the first table is ommited in the result of a SQL. Is it possible to make a statement as in VFP with »LEFT JOIN« option in FP 2.6? I know I could make a solution programming a DO... loop, but I prefer using a simple and faster SQL statement.
>
>Thanks, Zlatko.


If we were to introduce Visual FoxBase+, would we be able to work from the dotNet Prompt?


From Top 22 Developer Responses to defects in Software
2. "It’s not a bug, it’s a feature."
1. "I thought I fixed that."


All my FoxTalk and other articles are available on my web site.


Unless specifically identified otherwise, anthing posted here is purely my opinion and may or may not reflect the policies or practices of Microsoft.
Previous
Reply
Map
View

Click here to load this message in the networking platform