Selecting Data from a Table

  • To query all data from a table, use SELECT * FROM table_name
  • To select specific columns, replace * with the column names, e.g., 
SELECT first_name , last_name 
FROM employees;
  • You can change the order of the columns in the query

Using the WHERE Clause

  • The WHERE clause is used to filter data based on specific criteria
  • Example:
SELECT * FROM employees WHERE employee_ID = 1
  • You can use various operators, such as =>>=<<=!=

Examples of Using the WHERE Clause

Find all employees with a specific first name: 

SELECT * FROM employees WHERE first_name = 'SpongeBob'

Find all employees with an hourly pay greater than or equal to $15: 

SELECT * FROM employees WHERE hourly_pay >= 15

Find all employees with a hire date less than or equal to a specific date: 

SELECT * FROM employees WHERE hire_date <= '2023-01-03'

Using the NOT Operator

  • The NOT operator is used to find data that does not match a specific criteria
  • Example: SELECT * FROM employees WHERE employee_ID != 1
  • You can use the IS NOT NULL or IS NULL operators to check for null values

Best Practices

  • Use specific columns instead of * to reduce the amount of data returned
  • Use the WHERE clause to filter data based on specific criteria
  • Use various operators and the NOT operator to refine your queries