Advertisement

05.12.2008 at 10:19AM PDT, ID: 23395247
[x]
Attachment Details

Faster Alternative To UNION query

Asked by advlgx in MS SQL Server, SQL Server 2005

Tags: SQL

Is there a better way to get a result set from selects on multiple tables other than UNION ALL? It seems rather slow to me. Is there another best practice for a scenario like the following code?Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
Select 'RET' as type, entry_date, Amount, Description, '' as Status from Client0.dbo.invoice_retainers
where Client_id = 1
 
UNION ALL
Select 'INV' as type, invoice_date as entry_date, cpTotalDue as Amount, Invoice_Number as Description, status 
from Client0.dbo.invoice
where Bill_To_Client_Id = 1
 
UNION ALL
Select 'PYMT' as type, payment_date as entry_date, Amount, Reference as description, '' as status 
from Client0.dbo.invoice_payment
where Client_id = 1
 
Order by entry_date desc
 
Keywords: Faster Alternative To UNION query
 
Loading Advertisement...
 
[+][-]05.12.2008 at 10:20AM PDT, ID: 21548807

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]05.12.2008 at 10:29AM PDT, ID: 21548877

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: MS SQL Server, SQL Server 2005
Tags: SQL
Sign Up Now!
Solution Provided By: chapmandew
Participating Experts: 3
Solution Grade: A
 
 
[+][-]05.12.2008 at 10:49AM PDT, ID: 21549041

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]05.12.2008 at 10:57AM PDT, ID: 21549119

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.12.2008 at 10:58AM PDT, ID: 21549128

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.12.2008 at 11:06AM PDT, ID: 21549201

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628