11. Select Statement

  • Used to retrieve data from one or more table in the database.
  • Allows you to specify from which column you want to retrieve from the table.
  • WHERE clause can to used to filter the data by applying some condition.
  • Various functions like sum(), count(), etc. can be used with SELECT statement.
  • Can also used to join multiple table together to retrieve data.
  • DISTINCT key is used only to return unique value from the record.
Syntax   
  • SELECT column1,column2  FROM table_name  WHERE condition;

            E.g.

    •  SELECT first_name, last_name FROM employees   WHERE department = 'Sales';

  • SELECT * FROM table_name; //* means all records from the table.
         E.g.
    •   SELECT * FROM employees;
       
  • SELECT DISTINCT column1, column2, ...FROM table_name WHERE condition;
             E.g.
    •  SELECT DISTINCT first_name,   last_name FROM employees;

    •  SELECT DISTINCT department FROM employees;

Comments