-
Notifications
You must be signed in to change notification settings - Fork 196
/
Copy pathtest_union_ordering.sql
47 lines (39 loc) · 1.4 KB
/
test_union_ordering.sql
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
/* test set operator ordering for Patrick */
CREATE TABLE workers (
first_name VARCHAR2(100),
last_name VARCHAR2(100)
);
CREATE TABLE employees (
first_name VARCHAR2(100),
last_name VARCHAR2(100)
);
INSERT INTO workers (first_name, last_name) VALUES ('Ellen', 'Abel');
INSERT INTO workers (first_name, last_name) VALUES ('Herman', 'Baer');
INSERT INTO workers (first_name, last_name) VALUES ('Sarah', 'Bell');
INSERT INTO workers (first_name, last_name) VALUES ('Anthony', 'Cabrio');
INSERT INTO employees (first_name, last_name) VALUES ('Sundar', 'Ande');
INSERT INTO employees (first_name, last_name) VALUES ('Amit', 'Banda');
INSERT INTO employees (first_name, last_name) VALUES ('Alexis', 'Bull');
INSERT INTO employees (first_name, last_name) VALUES ('Scott', 'Davidson');
SELECT first_name, last_name FROM workers;
SELECT first_name, last_name FROM employees;
/*
Simple union. No Order By.
Seems to sort by the first column in ascending order
*/
SELECT last_name AS lname, first_name FROM workers
UNION
SELECT last_name, first_name FROM employees;
/*
Simple union. No order by. Using firstname as first column
Still sorts by the first column: first_name
*/
SELECT first_name, last_name FROM workers
UNION
SELECT first_name, last_name FROM employees;
/*
Add an alias, to match the example from Patrick
*/
SELECT first_name AS fname, last_name FROM workers
UNION
SELECT first_name, last_name FROM employees;