Stats

3554 Contributors: 92
2017-07-26
Licensed under: CC-BY-SA

Not affiliated with Stack Overflow
Rip Tutorial: info@zzzprojects.com

Download eBook

SELECT

Download sql eBook

Introduction

The SELECT statement is at the heart of most SQL queries. It defines what result set should be returned by the query, and is almost always used in conjunction with the FROM clause, which defines what part(s) of the database should be queried.

Syntax

  • SELECT [DISTINCT] [column1] [, [column2] ... ]
    FROM [table]
    [ WHERE condition ]
    [ GROUP BY [column1] [, [column2] ... ]

    [ HAVING [column1] [, [column2] ... ]

    [ ORDER BY ASC | DESC ]

Remarks

SELECT determines which columns' data to return and in which order FROM a given table (given that they match the other requirements in your query specifically - where and having filters and joins).

SELECT Name, SerialNumber
FROM ArmyInfo

will only return results from the Name and Serial Number columns, but not from the column called Rank, for example

SELECT *
FROM ArmyInfo

indicates that all columns will be returned. However, please note that it is poor practice to SELECT * as you are literally returning all columns of a table.

Related Examples