Reference no: EM13930547
SQL UNION and UNION ALL
UNION
The UNION command is used to select related information from two tables, much like the JOIN
command. However, when using the UNION command all selected columns need to be of the same
data type.
Note: With UNION, only distinct values are selected.
SQL Statement 1
UNION
SQL Statement 2
|
Employees_Norway:
E_ID
|
E_Name
|
01
|
Hansen, Ola
|
02
|
Svendson, Tove
|
03
|
Svendson, Stephen
|
04
|
Pettersen, Kari
|
Employees_USA:
E_ID
|
E_Name
|
01
|
Turner, Sally
|
02
|
Kent, Clark
|
03
|
Svendson, Stephen
|
04
|
Scott, Stephen
|
Using the UNION Command
Example
List all different employee names in Norway and USA:
SELECT E_Name FROM Employees_Norway
UNION
SELECT E_Name FROM Employees_USA
|
Result
E_Name
|
Hansen, Ola
|
Svendson, Tove
|
Svendson, Stephen
|
Pettersen, Kari
|
Turner, Sally
|
Kent, Clark
|
Scott, Stephen
|
Note: This command cannot be used to list all employees in Norway and USA. In the example
above we have two employees with equal names, and only one of them is listed. The UNION
command only selects distinct value
UNION ALL
The UNION ALL command is equal to the UNION command, except that UNION ALL selects all values.
SQL Statement 1
UNION ALL
SQL Statement 2
|
Using the UNION ALL Command
Example
List all employees in Norway and USA:
SELECT E_Name FROM Employees_Norway
UNION ALL
SELECT E_Name FROM Employees_USA
|
Result
E_Name
|
Hansen, Ola
|
Svendson, Tove
|
Svendson, Stephen
|
Pettersen, Kari
|
Turner, Sally
|
Kent, Clark
|
Svendson, Stephen
|
Scott, Stephen
|
Calculate the final market value of the flour
: How does the income approach to measuring GDP differ from the expenditure approach? Explain the meaning of value added and its importance in the income approach. Consider the following data for the selling price at each stage in the production of ..
|
Evaluate triangle criticism with examples
: You are a financial advisor and your new client is Triangle Jones, a 32 year old Musician. In the first meeting Triangle tells you he only has faith in real assets. He believes only real assets create wealth in an economy and when you try to expla..
|
Does dissociative identity disorder exist
: Does dissociative identity disorder exist? How might you assess its presence? Provide the rationale for your response based on scientific evidence from the professional literature.
|
Produced the larger amount of assets on the balance sheet
: Which method, FIFO or LIFO, produced the larger amount of assets on the balance sheet?
|
Explain union command
: The UNION command is used to select related information from two tables, much like the JOIN command. However, when using the UNION command all selected columns need to be of the same data type.
|
Economic theory and the available empirical evidence
: Discuss whether economic theory and the available empirical evidence justifies high executive compensation.
|
Determine the efficiency of the screw
: In testing the design of the screw-lift jack shown, 12 turns of the handle are required to elevate the lifting pad 1 in. If a force F = 10 lb applied normal to the crank is required to elevate a load L = 2700 lb, determine the efficiency e of the ..
|
What are the philosophical origins of each approach
: What are the philosophical origins of each approach, What are the goals of each approach and What are some techniques and strategies used by each approach
|
Methods for forecasting exchange rates
: Explain two of the methods for forecasting exchange rates and provide examples of how they might work.
|