Loading workspace environment...
Learn how to create tables with data types, insert records, and query datasets using SELECT, WHERE, ORDER BY, and LIMIT.
CREATE TABLE users (id INTEGER PRIMARY KEY, email TEXT NOT NULL);Creates a relational table schema.SELECT col1, col2 FROM table WHERE condition ORDER BY col1 DESC LIMIT 10;Standard declarative data query.-- Create employees table
CREATE TABLE employees (
id INTEGER PRIMARY KEY,
name TEXT NOT NULL,
department TEXT NOT NULL,
salary INTEGER NOT NULL,
hired_year INTEGER NOT NULL
);
-- Seed records
INSERT INTO employees VALUES (1, 'Ada Lovelace', 'Engineering', 140000, 2021);
INSERT INTO employees VALUES (2, 'Alan Turing', 'Engineering', 155000, 2019);
INSERT INTO employees VALUES (3, 'Grace Hopper', 'Management', 160000, 2018);
INSERT INTO employees VALUES (4, 'Claude Shannon', 'Research', 135000, 2022);
INSERT INTO employees VALUES (5, 'Margaret Hamilton', 'Engineering', 150000, 2020);
-- Query engineering staff earning >= 145000 sorted by salary
SELECT name, department, salary, hired_year
FROM employees
WHERE department = 'Engineering' AND salary >= 145000
ORDER BY salary DESC;name | department | salary | hired_year
-------------------+-------------+--------+-----------
Alan Turing | Engineering | 155000 | 2019
Margaret Hamilton | Engineering | 150000 | 2020SELECT * FROM users WHERE status = NULL;SELECT * FROM users WHERE status IS NULL;Architectural Explanation: In SQL, NULL represents an unknown value. Standard equality (`= NULL`) always evaluates to UNKNOWN. Always use `IS NULL` or `IS NOT NULL`.
Write a query on the `employees` table to return the top 2 highest earning employees across all departments who were hired after 2019.