-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathunion_queries.sql
More file actions
98 lines (87 loc) · 1.98 KB
/
Copy pathunion_queries.sql
File metadata and controls
98 lines (87 loc) · 1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
-- Create missing Employee table
DROP TABLE SalesLT.Employee;
CREATE TABLE SalesLT.Employee
(
EmployeeID INT IDENTITY PRIMARY KEY,
FirstName VARCHAR(30),
LastName VARCHAR(30)
);
GO
INSERT INTO SalesLT.Employee (FirstName, LastName)
VALUES
('Kyoko', 'Mahr'),
('Miss', 'Donahue'),
('Keila', 'Dau'),
('Despina', 'Stcyr'),
('Ricardo', 'Casado'),
('Callie', 'Bateman'),
('Boris', 'Sutter'),
('Ellan', 'Nuckols'),
('Colene', 'Bernett'),
('Grant', 'Scarbrough'),
('Johnetta', 'Lutz'),
('Eldridge', 'Poynor'),
('Aleisha', 'Engelhardt'),
('Janetta', 'Mcpartland'),
('Kiley', 'Briley'),
('Stefania', 'Feth'),
('Dortha', 'Westberry'),
('Tanya', 'Mazurek'),
('Reanna', 'Hydrick'),
('Tereasa', 'Brasel'),
('Lyndia', 'Hansen'),
('Ilse', 'Silvestri'),
('Kara', 'Votaw'),
('Bronwyn', 'Lobaugh'),
('Hobert', 'Strub'),
('Sheryll', 'Lague'),
('Keitha', 'Eaglin'),
('Sherry', 'Gearhart'),
('Kathryn', 'Boose'),
('Clyde', 'Mastroianni'),
('Violeta', 'Quan'),
('Melanie', 'Pryce'),
('Pamella', 'Dimery'),
('Aleen', 'Solt'),
('Temple', 'Iacovelli'),
('Esperanza', 'Ashline'),
('Leah', 'Wooley'),
('Jocelyn', 'Hayslip'),
('Karissa', 'Wiley'),
('Denise', 'Fazenbaker'),
('Myrle', 'Heaney'),
('Edward', 'Wing'),
('Yetta', 'Bowsher'),
('Athena', 'Ouzts'),
('Mona', 'Atencio'),
('Ozella', 'Conyers'),
('Roy', 'Biscoe'),
('Barney', 'York'),
('Raisa', 'Scaglione'),
('Easter', 'Rodriguez'),
('Donna', 'Carreras');
GO
SELECT firstname, lastname FROM SalesLT.Employee;
SELECT firstname, lastname FROM SalesLT.Customer
ORDER BY lastname;
-- create new table and copy distinct data from SAlesLT.customer (which has duplicates)
select distinct firstname, lastname
into customerCOPY
from SalesLT.Customer
-- union
SELECT FirstName, LastName
FROM SalesLT.Employee
UNION
SELECT FirstName, LastName
FROM dbo.Customercopy
ORDER BY LastName;
-- union all
SELECT FirstName, LastName, 'Employee' AS Type
FROM SalesLT.Employee
UNION ALL
SELECT FirstName, LastName, 'Customer'
FROM dbo.Customercopy
ORDER BY LastName;
GO
select * from temp
ORDER BY lastname;