This is a detailed tutorial for the SQL Select Statement. Learn how you can fetch data or retrieve records from the database tables using the select query.
Use of SQL Select
Select Statement in SQL is used to select the records from the database tables. In other words, to fetch data from the database, we make use of the select statement. The SQL Select command returns result-set which is basically the data of tables in tabular form. A Statement in SQL is also called a Query, so SQL Select Statement is having the same meaning as SQL select query.
Now, this statement gives us the flexibility of selecting either the whole table or only a few columns. Moreover, we can use multiple different logics and other SQL statements like the WHERE statement to fetch only those table rows that satisfy a condition.
SQL Select Statement Syntax
The basic syntax for the SQL Select is written below.
SELECT col_1, col_2, ...
Here col_1 and col_2 represent two different columns of a database table file the table_name is the actual name of the table defined in the database itself. You can one or more table columns using this statement. Make sure the column names are separated with commas.
In case you want to select or fetch all the columns of the table then you can use the * symbol instead of writing the comma-separated names for all columns. The syntax for the same is defined below.
SELECT * FROM table_name;
Further, the other SQL Statements like WHERE condition syntax can be added along with syntax which we’ll discuss later in the WHERE statement article separately. Here we’re just discussing the basic Syntax of SQL select statement.
SQL Select Example
We have a demo database. Now we’ll first select some particular columns and then all of the columns from a particular table using the SQL Select statement. The database name is
school and the table name from which we’re going to select records is named as
employees. We’re using MySQL Database with phpMyAdmin as the GUI for running queries and result showcase.
Selecting Particular Columns
We’ll select the first_name, last_name and the email columns of the table employees using the SQL select. The query is defined below and afterward, the screenshot for the out is given.
SELECT first_name, last_name, email FROM employees
Selecting All Columns
As defined in the syntax selection, to fetch all of the columns, instead of writing the names of each column, we’ll simply use the
* symbol. The query to fetch all the columns and rows for the table employees is written below.
SELECT * FROM employees
So, that’s all about SQL Select statement. It is often used along with other SQL statements like the WHERE statement which you may find out in one of the other articles.
I hope you find this guide useful. If so, do share it with others who are willing to learn SQL. If you have any questions related to this article, feel free to ask them in the comments section.
Helpful Associated Guide.
Also, don’t forget to Subscribe to WTMatter!