Writing Basic SQL Select Statements With Actual Demonstration

0
816

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:

The above command would display the whole table.

Now, we want to select two columns EMP_ID, EMPNAME, and CONTACT:

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:

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.

Looking for more source code? Type your keyword here here!

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.