login

SQL SELECT statement

SQL SELECT statement allows you to retrieve the data from one or more database table. Here is the common syntax of SQL SELECT statement:

SELECT column_list
FROM table_list
WHERE row_conditions
GROUP BY column_list
HAVING group_conditions
ORDER BY sort_list ASC | DESC


Basically SQL SELECT statement needs at least two criteria to retrieve the data:

  • Data columns to retrieve in the column list
  • Database table(s) where you retrieve the data.

Suppose you want to retrieve last name of employees in employees table you can perform the following query:

SELECT lastname
FROM employees

The query fetches the value from the column lastname from all rows in the employees table and returns the result or sometime we say result set.
 

You can also use SQL SELECT statement to retrieve multiple columns from a database table. In order to do so you must provide a comma between columns in the column list. For example, if you want to retrieve first name, last name and title of all employees you can execute the following query:

SELECT lastname, firstname, title
FROM employees

To retrieve all information of employee in the employees table, you can list all columns name and separate them by commas. In case a database table having many columns you can use a shorthand * to indicate that you want to retrieve all columns without explicitly specify them in the column list. For instance, you can retrieve all employee information by using the shorthand * as following:

SELECT *
FROM employees

In this tutorial, you’ve learn how to use simple SQL select statement to retrieve the data from a database table. You’ve learnt how to select a single column, multiple columns by separating them with a comma, and all columns by using the shorthand *. In the next tutorial you will use how to use the SQL SELECT statement with conditions to filter the rows in a database table.

Read On