Report Design
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Report Design
Message Icon Topic: Combining 'like' data Post Reply Post New Topic
Author Message
jmcd1965
Newbie
Newbie
Avatar

Joined: 07 Oct 2010
Location: United States
Online Status: Offline
Posts: 1
Quote jmcd1965 Replybullet Topic: Combining 'like' data
     Posted: 07 Oct 2010 at 7:23am
First post, so here goes:
I have 3 tables that each contain transaction data for a person, and one demographic table.  I'd like to combine the transaction information from all three tables into one activity log.  Example:
 
Demog Table
ID number
fname
lname
Address
 
A Trans Table
ID number
Date/time
location
info1
info2
 
B Trans Table
ID Number
Date/Time
location
info3
info4
 
C Trans Table
ID Number
Date/Time
location
info5
info6
 
Can anyone see the best join/linking configuration so I can create one activity log like below:
 
ID Number   Name  Date/Time   Location    info(1-6)
Thanks.
 
IP IP Logged
rvink
Groupie
Groupie
Avatar

Joined: 04 Feb 2008
Location: New Zealand
Online Status: Offline
Posts: 55
Quote rvink Replybullet Posted: 07 Oct 2010 at 4:30pm
Probably the best way is to write the query manually using a union:

select D.ID, D.fname, D.lname, T.Date/Time, T.Location, T.info1 as Info, 1 type
from Demog D left join Trans_A T on T.ID = D.ID

union all
select D.ID, D.fname, D.lname, T.Date/Time, T.Location, T.info2, 2
from Demog D left join Trans_A T on T.ID = D.ID

union all
select D.ID, D.fname, D.lname, T.Date/Time, T.Location, T.info3, 3
from Demog D left join Trans_B T on T.ID = D.ID

union all
select D.ID, D.fname, D.lname, T.Date/Time, T.Location, T.info4, 4
from Demog D left join Trans_B T on T.ID = D.ID

union all
select D.ID, D.fname, D.lname, T.Date/Time, T.Location, T.info5, 5
from Demog D left join Trans_C T on T.ID = D.ID

union all
select D.ID, D.fname, D.lname, T.Date/Time, T.Location, T.info6, 6
from Demog D left join Trans_C T on T.ID = D.ID

order by D.ID [...]


I used left joins so the person will be included in the report even if they have no activity in log A, B or C. I added the type so you can distinguish which log the record comes from, if required. I used union all to ensure duplicate records are included (union by itself removes duplicates).
IP IP Logged
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum