Writing Basic SQL Select Statements With Actual Demonstration

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

  1. SELECT

    A LISTING OF ONE OR MORE COLUMNS

  2. * / Asterisk

    Means all the columns from all tables in the from statement are to be returned.

  3. DISTINCT

    This is used to eliminate duplication of records.

  4. COLUMN

    Selects the name of column

  5. ALIAS

    Using an alias, you can set a unique or proper heading of a column

  6. FROM TABLE

    It uses to specify the target table containing the columns.

For example we have here a sample table named tblsampleemployee:

EMP_IDEMPNAMECONTACTSALARYDEPT_NAME
1Kobe Bryant789541250000SHIPPING
2Jordan Michael789541270000IT
3James BOnd123245645000SALES
4Anne Curtis787889835000SHIPPING
5John Wick1233455765000EXECUTIVE
6Hatch Glets6654878257000IT
7Xyre Anderson7877892348000SALES

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_IDEMPNAMECONTACT
1Kobe Bryant7895412
2Jordan Michael7895412
3James BOnd1232456
4Anne Curtis7878898
5John Wick12334557
6Hatch Glets66548782
7Xyre Anderson78778923

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.

5 thoughts on “Writing Basic SQL Select Statements With Actual Demonstration”

  1. 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

Leave a Comment