These are the records for my Compnay table:
Keyid Companynam
1 Texaco
2 Exxon
3 Shell
4 Mobil
These are from my Division table
Keyid Company_id Division
1 1 West
2 2 East
3 1 East
4 2 North
5 1 South
6 3 West
7 4 East
8 4 South
9 3 East
10 1 North
11 2 South
12 3 North
13 3 South
14 2 West
15 4 North
16 4 West
Company_ID in Division table is the FK from the COmpany table. Then run my sample code and you get:
Keyid Companynam Divid Division
1 Texaco 10 North
1 1 West
1 3 East
1 5 South
2 Exxon 14 West
2 2 East
2 4 North
2 11 South
3 Shell 13 South
3 6 West
3 9 East
3 12 North
4 Mobil 16 West
4 7 East
4 8 South
4 15 North
>I changed the tables and your code
>
>table 1: COMPANY
>companynam C,30
>ckey N,3
>
>Table 2: DIVISION
>div_name C,50
>ckey N,3
>
>and in your code:
>
>close tables all
>select a.ckey, a.companynam, b.ckey DivID, b.div_name ;
> from Company A join Division B on a.ckey = b.ckey ;
> group by a.ckey into cursor crsTemp1 nofilter
>
>select a.ckey, a.companynam, b.ckey DivID, b.div_name ;
> from Company A join Division B on a.ckey = b.ckey ;
> where b.ckey not in (select DivID from crsTemp1) ;
> into cursor crsTemp2 nofilter
>
>select * from crsTemp1 ;
> union ;
>select ckey, space(30) CompanyNam, DivID, div_name ;
> from crsTemp2 order by 1, 2 desc ;
> into cursor crsResults nofilter
>
>*select crsTemp1
>*browse last nowait
>*select crsTemp2
>*browse last nowait
>select crsResults
>browse last nowait
>
>I come up with ONLY 1 record even though I have 3 child records.
Mark McCasland
Midlothian, TX USA