Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

pull all rows from two tables with the same field names Crystal 2013 2

Status
Not open for further replies.

jchewsmith

Technical User
Nov 20, 2006
161
US
I am trying to pull information from two tables that have the same table structure but different info in each table. (Example: There is 500 address in one table and 350 addresses in a second table and I want to somehow link them and pull all 850 addresses into the crystal report.)

table 1
1230 any time st
2415 los angles st.

table 2
4556 main st
899 2nd st.

Report
1230 any time st
2415 los angels st.
4556 main st
899 2nd st.
 
The simplest solution would be to write a command with a union statement that would then in essence merge the corresponding fields from each table, as in:

Select table1.field1, table1.field2, table1.field3
From table1
Where <your selection criteria>
Union
Select table2.field1, table2.field2, table2.field3
From table2
Where <your selection criteria>
Order by 1,2,3


Just make sure you use the same order when specifying fields in each table. This will result in command.field1 containing both field1 fields. If you want to add an order to the command, do it at the end of the entire command, and use ordinal numbers to specify which field(s) to sort by or leave out the line altogether if you wish.

-LB
 
Another approach is to apply names to the fields in the SQLL Command, so that would look something like:

SELECT table1.keyfield
,table1.address as home_address
,table2.address as work_address
from table1
join table2 on table1.keyfield = table2.keyfield
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top