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
- SELECT
A LISTING OF ONE OR MORE COLUMNS
- * / Asterisk
Means all the columns from all tables in the from statement are to be returned.
- DISTINCT
This is used to eliminate duplication of records.
- COLUMN
Selects the name of column
- ALIAS
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:
EMP_ID | EMPNAME | CONTACT | SALARY | DEPT_NAME |
1 | Kobe Bryant | 7895412 | 50000 | SHIPPING |
2 | Jordan Michael | 7895412 | 70000 | IT |
3 | James BOnd | 1232456 | 45000 | SALES |
4 | Anne Curtis | 7878898 | 35000 | SHIPPING |
5 | John Wick | 12334557 | 65000 | EXECUTIVE |
6 | Hatch Glets | 66548782 | 57000 | IT |
7 | Xyre Anderson | 78778923 | 48000 | SALES |
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.
Syntax:
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:
EMP_ID | EMPNAME | CONTACT |
1 | Kobe Bryant | 7895412 |
2 | Jordan Michael | 7895412 |
3 | James BOnd | 1232456 |
4 | Anne Curtis | 7878898 |
5 | John Wick | 12334557 |
6 | Hatch Glets | 66548782 |
7 | Xyre Anderson | 78778923 |
Select Statement to eliminate duplication Records.
Syntax:
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
For Inquiries
If you have any questions about How to Write a Basic SQL SELECT Statement, please leave a comment below.
The video show the basic SQL with Select Statement and I learned a lot for this video tutorial the video is clear and the demonstration is clear by discuss step by step
thanks.
Thank u for teaching us this totorial it is really helpfull 😁salamat gid the best kagid ya sir
Thank u for teaching us this totorial this is really helpful and keep making videos 😀 salamt gid sir <3
Thanks for teaching us this totorial I hope I could learn it as soon as possible 😀thank u sir you’re the best 💯