CodeEraFree roadmap

SQL Practice / Employees table

SQL practice table: employees (create and insert script)

Run this once, then use it for most of the practice sets.

Most CodeEra practice sets use one table, employees, with 30 rows. Copy the script below into MySQL, MariaDB or any SQL editor and run it. It creates the table and inserts all 30 rows.

CREATE TABLE employees (
  emp_no       INT         NOT NULL,
  first_name   VARCHAR(20) NOT NULL,
  last_name    VARCHAR(20) NOT NULL,
  salary       INT,
  birth_date   DATE        NOT NULL,
  gender       ENUM('M','F') NOT NULL,
  joining_date DATE        NOT NULL,
  department   VARCHAR(20),
  PRIMARY KEY (emp_no)
);

INSERT INTO employees (emp_no, first_name, last_name, salary, birth_date, gender, joining_date, department)
VALUES (1001, 'James', 'Bond', 45300, '1998-01-19', 'M', '2020-11-29', 'Marketing'),
  (1002, 'Robert', 'Lee', 69410, '1998-09-02', 'M', '2019-12-26', 'IT'),
  (1003, 'Mary', 'Wood', 39518, '1997-11-07', 'F', '2019-09-12', 'Business Development'),
  (1004, 'John', 'Cole', 36264, '1999-02-01', 'M', '2021-04-14', 'HR'),
  (1005, 'Jennifer', 'Gill', 48941, '1996-06-05', 'F', '2019-06-28', 'Marketing'),
  (1006, 'Michael', 'Watts', 23800, '1999-04-16', 'M', '2022-06-09', 'HR'),
  (1007, 'David', 'Mills', 39400, '1998-04-26', 'M', '2021-10-17', 'IT'),
  (1008, 'William', 'Hill', 26392, '1999-10-21', 'M', '2019-09-30', 'Business Development'),
  (1009, 'Linda', 'Potter', 55231, '1998-01-24', 'F', '2021-08-07', 'Finance'),
  (1010, 'Richard', 'Martin', 25600, '1996-08-07', 'M', '2021-03-23', 'IT'),
  (1011, 'Susan', 'Hall', 54152, '1999-12-27', 'F', '2020-08-07', 'Finance'),
  (1012, 'Joseph', 'Turner', 60556, '1997-05-13', 'M', '2019-09-02', 'Marketing'),
  (1013, 'Mary', 'Gill', 58246, '1999-01-21', 'F', '2021-04-30', 'Business Development'),
  (1014, 'Thomas', 'Ryan', 23676, '1996-10-12', 'M', '2022-03-02', 'IT'),
  (1015, 'Charles', 'Williams', 57226, '2000-01-29', 'M', '2019-11-05', NULL),
  (1016, 'Jessica', 'Clark', NULL, '2000-01-25', 'F', '2020-01-24', 'IT'),
  (1017, 'Nancy', 'Parker', 66900, '1996-10-24', 'F', '2022-01-09', 'Finance'),
  (1018, 'Betty', 'Barker', 35288, '1998-11-13', 'F', '2019-12-26', 'HR'),
  (1019, 'Christopher', 'Gibson', 59341, '1998-04-23', 'M', '2019-05-02', 'Marketing'),
  (1020, 'Daniel', 'Elliott', 44012, '1999-01-21', 'M', '2023-01-08', 'IT'),
  (1021, 'David', 'Mills', NULL, '1998-01-24', 'M', '2019-12-26', 'IT'),
  (1022, 'Sarah', 'Harrison', 44692, '1996-03-20', 'F', '2020-05-03', 'Finance'),
  (1023, 'Matthew', 'Hill', 41365, '1998-05-16', 'M', '2019-05-23', 'IT'),
  (1024, 'Anthony', 'Miller', 56794, '1996-06-30', 'M', '2019-02-28', 'Business Development'),
  (1025, 'Mark', 'Wood', 65120, '1998-10-29', 'M', '2020-07-30', 'Business Development'),
  (1026, 'Elizabeth', 'Walker', 47030, '1998-08-11', 'F', '2021-06-18', NULL),
  (1027, 'Barbara', 'Anderson', NULL, '1999-12-27', 'F', '2021-03-14', 'HR'),
  (1028, 'Jessica', 'Clark', 63836, '1998-01-24', 'F', '2021-05-23', 'IT'),
  (1029, 'Nancy', 'Cole', 63669, '2000-01-26', 'F', '2019-12-26', 'Finance'),
  (1030, 'Joe', 'Brooks', 44000, '1999-08-05', 'M', '2021-03-09', 'Business Development');

emp_no is the primary key. salary, department and a few other values are left empty (NULL) on purpose, because real data has gaps and several questions are about them.

What is in the table

emp_nofirst_namelast_namesalarybirth_dategenderjoining_datedepartment
1001JamesBond453001998-01-19M2020-11-29Marketing
1002RobertLee694101998-09-02M2019-12-26IT
1003MaryWood395181997-11-07F2019-09-12Business Development
1004JohnCole362641999-02-01M2021-04-14HR
1005JenniferGill489411996-06-05F2019-06-28Marketing
1006MichaelWatts238001999-04-16M2022-06-09HR
1007DavidMills394001998-04-26M2021-10-17IT
1008WilliamHill263921999-10-21M2019-09-30Business Development
1009LindaPotter552311998-01-24F2021-08-07Finance
1010RichardMartin256001996-08-07M2021-03-23IT
1011SusanHall541521999-12-27F2020-08-07Finance
1012JosephTurner605561997-05-13M2019-09-02Marketing
1013MaryGill582461999-01-21F2021-04-30Business Development
1014ThomasRyan236761996-10-12M2022-03-02IT
1015CharlesWilliams572262000-01-29M2019-11-05NULL
1016JessicaClarkNULL2000-01-25F2020-01-24IT
1017NancyParker669001996-10-24F2022-01-09Finance
1018BettyBarker352881998-11-13F2019-12-26HR
1019ChristopherGibson593411998-04-23M2019-05-02Marketing
1020DanielElliott440121999-01-21M2023-01-08IT
1021DavidMillsNULL1998-01-24M2019-12-26IT
1022SarahHarrison446921996-03-20F2020-05-03Finance
1023MatthewHill413651998-05-16M2019-05-23IT
1024AnthonyMiller567941996-06-30M2019-02-28Business Development
1025MarkWood651201998-10-29M2020-07-30Business Development
1026ElizabethWalker470301998-08-11F2021-06-18NULL
1027BarbaraAndersonNULL1999-12-27F2021-03-14HR
1028JessicaClark638361998-01-24F2021-05-23IT
1029NancyCole636692000-01-26F2019-12-26Finance
1030JoeBrooks440001999-08-05M2021-03-09Business Development

Practice sets that use this table

Prefer the PDF versions? Create table PDF and insert data PDF.