SQLTutorials

SQL SELECT Statement

The SQL SELECT Statement

The SQL SELECT statement is used to select data from one or more tables. The data returned is stored in a result table, called the result-set. The following shows the basic syntax of the SELECT statement that selects data from a single table.

SQL SELECT Syntax

SELECT column1_name, column2_name, etc
FROM table_name;

Here, column1_name, column2_name, … are the field names of the table the data will be selected from.

How to Select All Fields From A Table in SQL?

If you want to select all the fields available in the table, you use asterisk (*) operator instead if specifying column names. Here is the syntax:

SELECT * FROM table_name;

Order of Evaluation in SQL

First, the database system will assess the FROM clause of the SELECT statement before moving on to the SELECT clause itself to complete the evaluation. A good analogy would be like: from table x, select the data in column x .

The Semicolon in SQL

In SQL programming, the semicolon character (;) serves as a statement terminator. Many developers do not include a “;” as a statement terminator in SQL, but this would cause a great deal of problems if it suddenly became required for later versions of Microsoft SQL. Moreover, if you are going to execute two SQL SELECT statements, you will need to separate them with the semicolon (;).

SELECT in SQL, Capital or Small Letters?

The SQL keywords, such as SELECT and FROM, should always be written in all capital letters, whereas identifiers, such as table and column names, will always be written in lowercase characters.

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button