SQL SELECT Statement


The SQL SELECT statement is the most frequently used SQL query or command. It is used to fetch or retrieve all data (columns and rows) or partial (specific columns) data from a database table.

The SQL SELECT command returns matched query data in the form of table (rows and columns).
These tables are called result set or result table.


Search Keys

  • sql select query
  • select statement
  • sql select table
  • sql server select where
  • sql unique select
  • select tables from database
  • select statement in sql
  • sql command select
  • select sql query
  • sql query select where
  • select 1 sql
  • sql select examples
  • sql server select example
  • sql select where syntax
  • select sql database
  • basic sql select statements
  • select syntax sql server
  • sql select command examples
  • mssql select syntax
  • sql select on select
  • sql select query examples
  • syntax of select statement

Sql Select Query Syntax

The below syntax is used to select specific column(s) from the specific table.


SELECT 
column_name1, column_name2, column_nameN 
FROM table_name;

The below syntax is used to select all column(s) from the specific table.


SELECT * FROM table_name;

Note:- You can write all SQL statements in a single line or multiple line.

  • SELECT - The SELECT command specifies the list of columns that are retrieved from the table.
  • FROM - The FROM command specifies from where data should be retrieved.

Sample Database Table - Books

BookId BookName BookPrice RelYear DomainName AuthorName
1 SQL Puzzles & Answers 130 2009 Database Padmavathi
2 Transact SQL Cookbook 80 2008 Programming Bala Murugan
3 Structured Query Language for all RDBMS 140 2008 Administration Hari Krishnan
4 Oracle 11g PL/SQL Programming 180 2010 Administration Balan
5 Programming With MySQL 199.97 2006 Programming Pandurengan
6 SQL Server Query Performance Tuning 120 2011 Security Vidyavathi
7 Red Gate Guide to SQL Server 165 2014 Administration Hanumanthan
8 MySql Database Internals 205 2013 Security Hanumanthan
9 Data Analysis Using SQL 60 2009 Database Nirmala
10 Getting Started With SQL 145 2015 Security Sakunthala
11 Pro SQL Azure 136.33 2011 Database Pandurengan
12 Oracle Interview Questions 125 2013 Database Balan

SELECT Specific Column Example

The following SQL SELECT statement selects the "BookName" and "BookPrice" columns from the "Books" table:


SELECT 
BookName, BookPrice 
FROM Books;

Note: Column names are separated by commas(,).

The result of above query is:

BookName BookPrice
SQL Puzzles & Answers 130
Transact SQL Cookbook 80
Structured Query Language for all RDBMS 140
Oracle 11g PL/SQL Programming 180
Programming With MySQL 199.97
SQL Server Query Performance Tuning 120
Red Gate Guide to SQL Server 165
MySql Database Internals 205
Data Analysis Using SQL 60
Getting Started With SQL 145
Pro SQL Azure 136.33
Oracle Interview Questions 125

SELECT * Example

The following SQL SELECT statement selects all the column names or fields of "Books" table:


SELECT * FROM Books;

Note: '*' is a special characters, which is used to select all columns from the table.

The result of above query is:

BookId BookName BookPrice RelYear DomainName AuthorName
1 SQL Puzzles & Answers 130 2009 Database Padmavathi
2 Transact SQL Cookbook 80 2008 Programming Bala Murugan
3 Structured Query Language for all RDBMS 140 2008 Administration Hari Krishnan
4 Oracle 11g PL/SQL Programming 180 2010 Administration Balan
5 Programming With MySQL 199.97 2006 Programming Pandurengan
6 SQL Server Query Performance Tuning 120 2011 Security Vidyavathi
7 Red Gate Guide to SQL Server 165 2014 Administration Hanumanthan
8 MySql Database Internals 205 2013 Security Hanumanthan
9 Data Analysis Using SQL 60 2009 Database Nirmala
10 Getting Started With SQL 145 2015 Security Sakunthala
11 Pro SQL Azure 136.33 2011 Database Pandurengan
12 Oracle Interview Questions 125 2013 Database Balan

Search Keys

  • sql select in select statement
  • sql select from table where
  • multiple select sql
  • select update sql
  • sql select where in list
  • sql select values
  • sql select as table
  • sql select row
  • retrieve sql
  • sql retrieve data
  • retrieve data from sql
  • retrieve data from sql database
  • sql query to retrieve data from table
  • sql query to retrieve data
  • select from query
  • sql multiple select
  • sql select into table
  • sql select field
  • sql select specific columns
  • select into existing table
  • select unique sql
  • sql server select from where
  • select into variable