sqlbeginner10 minutes

Create a Basic Employee Directory Table and Query

Build a simple employee directory table and write a query to retrieve filtered information about employees, practicing basic SQL data modeling and SELECT queries.

Challenge prompt

You are tasked with creating a simple employee directory. Start by creating a table named 'employees' with the following columns: employee_id (integer), first_name (text), last_name (text), department (text), and salary (integer). After creating and inserting sample data (3-5 rows), write a query to select all employees from the 'Sales' department whose salary is greater than 50000.

Guidance

  • Define the table schema with appropriate data types.
  • Insert sample data into the table.
  • Write a SELECT query with WHERE conditions to filter by department and salary.

Hints

  • Use CREATE TABLE syntax with specified columns.
  • Use INSERT INTO to add multiple rows of employees.
  • Use WHERE clause with multiple conditions combined with AND.

Starter code

CREATE TABLE employees (
  employee_id INT,
  first_name TEXT,
  last_name TEXT,
  department TEXT,
  salary INT
);

INSERT INTO employees VALUES
(1, 'John', 'Doe', 'Sales', 60000),
(2, 'Jane', 'Smith', 'Marketing', 45000),
(3, 'Emily', 'Jones', 'Sales', 52000),
(4, 'Michael', 'Brown', 'Engineering', 70000),
(5, 'Anne', 'Clark', 'Sales', 48000);

-- Write your SELECT query below to find sales employees with salary > 50000

Expected output

employee_id | first_name | last_name | department | salary ------------|------------|-----------|------------|------- 1 | John | Doe | Sales | 60000 3 | Emily | Jones | Sales | 52000

Core concepts

CREATE TABLEINSERT INTOSELECTWHERE clause

Challenge a Friend

Send this duel to someone else and see if they can solve it.