Skip to content

Commit

Permalink
add: unions
Browse files Browse the repository at this point in the history
  • Loading branch information
thutasann committed Jan 29, 2025
1 parent a5bb7d2 commit fb11278
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions sql/full_course/clause/unions.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
CREATE TABLE income (
income_id INT PRIMARY KEY AUTO_INCREMENT,
income_name VARCHAR(25),
amount DECIMAL(5,2)
);

CREATE TABLE expenses (
expense_id INT PRIMARY KEY AUTO_INCREMENT,
expense_name VARCHAR(25),
amount DECIMAL(5,2)
)

INSERT INTO income (income_name, amount)
VALUES ("orders", 100.00),
("merchandiese", 500.0),
("services", 125.312);


INSERT INTO expenses (expense_name, amount)
VALUES ("wages", -240.00),
("tax", -200.00),
("repairs", -120.00)

SELECT * FROM income
UNION
SELECT * FROM expenses;

-------------- Unions does allow duplicates

SELECT first_name, last_name FROM employees
UNION
SELECT first_name, last_name FROM customers;

INSERT INTO customers (first_name, last_name)
VALUES ("thuta", "sann updated")

0 comments on commit fb11278

Please sign in to comment.