Writing Basic SQL Select Statements With Actual Demonstration
This tutorial for beginners about Writing Basic SQL SELECT Statements is useful if you are trying to develop a system with a database. The SQL Select statement is used to extract data from the database.
You may also need to restrict all the columns you want to be displayed.
This lesson will show you all the SQL statements you need to perform these actions.
Capabilities of SQL SELECT Statements
A SELECT statement retrieves information from the database. With SELECT Statement, you can also do the following:
- Projection – You can choose the columns in the table that you want to returned by your query. It’s up to you to choose few or many columns of the table as you require.
- Selection – You can use various criteria to restrict the rows that you see.
- Joining – You can bring all the data together that is stored from different tables by creating a link between them.
Simplest Form of SELECT Statements, It includes the following:
Basic SQL Select Statements
A LISTING OF ONE OR MORE COLUMNS
- * / Asterisk
Means all the columns from all tables in the from statement are to be returned.
This is used to eliminate duplication of records.
Selects the name of column
Using an alias, you can set a unique or proper heading of a column
- FROM TABLE
It uses to specify the target table containing the columns.
For example we have here a sample table named tblsampleemployee:
Selecting All Columns
The SELECT statement tells what is to be returned. ‘*’means all the columns from all tables in the from statement are to be returned.
SELECT * FROM tblsampleemployee;
The above command would display the whole table.
Now, we want to select two columns EMP_ID, EMPNAME, and CONTACT:
SELECT EMP_ID, EMPNAME, CONTACT FROM tblsampleemployee ;
This would give the following result:
Select Statement to eliminate duplication Records.
SELECT EMP_ID, DISTINCT( EMPNAME) FROM tblsampleemployee;
So, in the query above we used “DISTINCT” keyword to eliminate duplicate records.
Video Tutorial of Writing basic SQL SELECT Statements
Watch the video tutorial here for complete practice with actual demonstration.
Download here the database used in the video demonstration
If you have any questions about How to Write a Basic SQL SELECT Statement, please leave a comment below.