How can I join tables without using union all?

How can I join tables without using union all?

Post by Wael Solima » Thu, 13 Mar 2003 20:11:07



Hi all
How can I join more than table with same structure without union all?
because I have many tables when I join it using union all the SQL
statement exudes max length of statement and give error
For example:
(Select Field1, Field2, Field3,... from database1..Table1 Inner join
database1..Table2 On ........
Union All
Select Field1, Field2, Field3,.... from database2..Table1 Inner join
database2..Table2 On .......
Union All)
and so on
I want to ask about any idea to join the tables
Thanks and best regards

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

 
 
 

How can I join tables without using union all?

Post by Dave Har » Thu, 13 Mar 2003 20:56:23


insert into a temporary table and then select from there:

select Field1, Field2, Field3,... into #tmptable from database1..Table1
Inner join database1..Table2 On ........
insert into #tmptable Field1, Field2, Field3,... from database2..Table1
Inner join database2..Table2 On ........etc...
select * from #tmptable

Cheers,
Dave


Quote:> Hi all
> How can I join more than table with same structure without union all?
> because I have many tables when I join it using union all the SQL
> statement exudes max length of statement and give error
> For example:
> (Select Field1, Field2, Field3,... from database1..Table1 Inner join
> database1..Table2 On ........
> Union All
> Select Field1, Field2, Field3,.... from database2..Table1 Inner join
> database2..Table2 On .......
> Union All)
> and so on
> I want to ask about any idea to join the tables
> Thanks and best regards

> *** Sent via Developersdex http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it!


 
 
 

1. Combining data from two tables (union /outer join ??)

Here is the newbee question of the day:

I have 2 tables call them A and B.   They each have a common field called
"UPN Reference".  I want to combine the two tables into a single table so
that I have the columns (and data) from both tables in one.  Some rows will
line up across the UPN and others wont.  So graphically the data will look
something like this in the new table:

  --------  New Table   ----------
 (A columns)      (B columns)

 ********
 ********
 ********
 ********    <-->      ********
 ********    <-->      ********
 ********    <-->      ********
 ********    <-->      ********
                              ********
                              ********
                              ********
                              ********

The end result will have data that has:

    A having no matches in B.
    A and B aligned across the UPN Reference.
    B with no matching A.

I am not sure if this should be some kind of union or a nested outer join?
Can someone give me the SQL for this?

Help!

Please email directly to me if possible.....I have had problems with news
lately.

Thanks,
Tim

2. Stored Procedure question

3. Update without using inner join

4. JDBC Driver for InterBase 4.0 [Linux Server]

5. Join 3 tables without TRANSFORM

6. MSDB database is suspect

7. Joining two tables without primary keys

8. Using Tables to join two other tables in SQL server or Access

9. Joining 5 tables vs. using temp table

10. How to use SUM without UNION, CASE or CURSOR

11. SQL Server Views without Unions

12. Exchange data between two databases without using a ##table