Back to: Structured Query Language (SQL)
We are continuing with our myDB database and the employees table created in a previous lesson.
We already know how to view the entire table, showing ALL rows and ALL columns.
SELECT * FROM employees;

Sometimes we don’t need ALL of the data. If you have been tasked with retrieving the full name of every employee. We can do this by amending our SELECT query:
SELECT first_name, last_name FROM employees;

Now try:
SELECT last_name, first_name FROM employees;
There is a WHERE clause we can use if we are looking for something specific, we can add some criteria:
SELECT *
FROM employees
WHERE employee_id = 1;
SELECT *
FROM employees
WHERE first_name = "Spongebob";
To find a list of all employees that have an hourly pay rate greater than or equal to $15:
SELECT *
FROM employees
WHERE hourly_pay >= 15;

Try this:
SELECT hire_date, first_name
FROM employees
WHERE hire_date <= "2023-01-03";
The NOT comparison operator “does not equal” is expressed as != :
SELECT *
FROM employees
WHERE employee_id != 1;
We can search for empty values by check if the field IS NULL :
SELECT *
FROM employees
WHERE hire_date IS NULL;
and vice versa:
SELECT *
FROM employees
WHERE hire_date IS NOT NULL;