Search

Friday, 6 September 2019

Introduction to SQL - SELECT Statement


SQL SELECT Statement

SQL SELECT statement pulls data from a table in the SQL database and display it in a table like structure called a result-set. You can select single column or multiple columns at once. Just list the column name or column names separated by commas from the table:

The SQL Statement Syntax

The general syntax for a simple SQL statement is

SELECT column-names
              FROM table-name;


Practical Examples


SQL SELECT Statement - Single Column

Below SQL Statement will return single Column [FirstName] from [Employees] table.

SELECT [FirstName]
            FROM [Employees];

SQL SELECT Statement – Multiple Columns
Below SQL Statement will return multiple Columns [FirstName],[LastName] from [Employees] table.

SELECT [FirstName], [LastName],
       FROM [Employees];

SQL SELECT Statement – All Columns

If used (*) instead of column name in SQL Statement it will return all Columns from [Employees] table. 

SELECT *
       FROM [Employees];

Caution: It’s not ideal to use Select all columns all the time if only need certain columns as that increase burden on SQL engine. We will discuss its effects on another day!


This concludes our study of the SQL Select Statement. In the next article, we will take a closer look at  DISTINCT and WHERE Keywords and how these used in SQL.

Below is a list of my favorite SQL books which I would recommend for you if you looking to enhance your knowledge on the topic.




Below is my favourite Forums for SQL