| Author: Manigandan 29 Jun 2009 | Member Level: Gold Points : 2 |
Hi,
Nice one keep posting more...
We can also use Union in a join Query like this,
SELECT employees.Lastname, employees.Firstname, invoices.Sale, invoices.Price FROM employees INNER JOIN invoices ON employees.id = invoices.EmployeeID UNION SELECT employees2.Lastname, employees2.Firstname, invoices.Sale, invoices.Price FROM employees2 INNER JOIN invoices ON employees2.id = invoices.EmployeeID;
Thanks, Mani
|
| Author: Viji RAJKUMAR 29 Jun 2009 | Member Level: Diamond Points : 2 |
hi Manig,
Thanks For your response.
In this article I took a very simple example to explain the difference between UNION and UNION ALL.
Event if we want to include specific where clause or ORDER by clause we can add it.
SELECT EmployeeID, lastName FROM [dbo].[Employees] ORDER BY EmpID
UNION
SELECT EmployeeID, Address FROM [dbo].[Employees1] WHERE EMPID NOT IN (1001,2001)
Note:
UNION ALL works faster than UNION as it does not perform select distinct.
If you know that you should combin all recordset use UNION ALL
|