SQLite Practice

mail@pastecode.io avatar
unknown
sql
7 months ago
1.8 kB
9
Indexable
Never
--https://sqliteonline.com/

CREATE TABLE IF NOT EXISTS Person(id INTEGER PRIMARY KEY AUTOINCREMENT, first_name CHARACTER(10), last_name CHARACTER(20));
CREATE TABLE IF NOT EXISTS Employee(id INTEGER PRIMARY KEY AUTOINCREMENT, name VARCHAR(10), last_name VARCHAR(20), salary DOUBLE, city CHAR(2));
CREATE TABLE IF NOT EXISTS Employees(id INTEGER PRIMARY KEY AUTOINCREMENT, name VARCHAR(10), last_name VARCHAR(20), salary DOUBLE);
CREATE TABLE IF NOT EXISTS Executives(id INTEGER PRIMARY KEY AUTOINCREMENT, name VARCHAR(10), last_name VARCHAR(20), salary DOUBLE);


/*
INSERT INTO Person (first_name, last_name) 
VALUES ('Joe', 'Smith'), ('Bob', 'Li'), ('Joe', 'Nell');
*/

/*
INSERT INTO Employee (name, last_name, salary, city) 
VALUES ('Joe', 'Diaz', 96000, 'NY'), ('Ron', 'Peter', 67000, 'NY'), ('Gary', 'Fife', 50000, 'SF'), ('Tom', 'Schwartz', 30000, 'SF'), 
		('John', 'Schwartz', 20000, 'SJ');
*/

/*
INSERT INTO Employees (name, last_name, salary) 
VALUES ('Joe', 'Diaz', 96000), ('Ron', 'Peter', 67000), ('Gary', 'Fife', 50000), ('Tom', 'Schwartz', 30000), 
		('John', 'Schwartz', 20000);
        
INSERT INTO Executives (name, last_name, salary) 
VALUES ('Tom', 'Bombadil', 12000), ('Gandalf', 'The Grey', 20000), ('Sundar', 'Pichai', 300000), ('Jann', 'Garcia', 500000), 
		('Un', 'Tipo', 300000000);  
*/

--SELECT * from Employee;
--SELECT * FROM Employee where city !='SF' 
--SELECT name, last_name, salary from Employees UNION SELECT name, last_name, salary from Executives
--SELECT name from Employee EXCEPT SELECT name from Employees
--ALTER TABLE Person RENAME id to person_id;
--SELECT name from Employee AS employee_name
--Cartesian Product: SELECT * FROM Employees CROSS JOIN Executives
--SELECT Employee.name, Employee.last_name, Employee.salary, city from Employee INNER JOIN Executives on Employee.salary = Executives.salary;