SELECT Statement in SQL – DML Statements



Now in this SQL Post we will learn Data Manipulation Language (DML) SELECT Statement.

SELECT Statement in SQL – DML Statements


SQL SELECT Statement – The SELECT statement is used to select / retrieve data from a table in the database. The SQL SELECT Statement is most commonly used statement.

The SELECT Statement query retrieve whole table data or some specific columns data from the table.

If we want to retrieve some data from table we need to write SELECT statement query in SQL.

In SELECT Statement we retrieve the data by columns wise.

The SQL SELECT Statement Syntax :

The SQL SELECT Syntax categorize in to two parts , first we retrieve all columns means full table data, second we retrieve some specific columns from a table.

SELECT all Columns data from a table

SELECT FROM  table_name ;

*  = indicate the retrieve all the columns from a table.
table_name = is the name of table from which the data is retrieved.

SELECT some columns data from a table

SELECT Col1, Col2, Col3  FROM  table_name

Col1, Col2, Col3  = is the column name from which data is retrieved.
table_name = is the name of table from which the data is retrieved.

Now, let’s take an example to understand more about SQL SELECT Statement.

SQL SELECT Statement Example :

First we create a new database in database server  and create a new table in database. After creating a table in database we apply SQL SELECT query on table to retrieve data from a table.

We have already learned CREATE Database and CREATE Table using CREATE DDL Statement in our previous SQL post.

Now, we have a table named “Student” with some columns like ID, Name, City, Email.

The SQL Student Table :

ID Name City Email
1 Meera Bombay meera@yahoo.com
2 Ram Surat ram@yahoo.com
3 Jay Bombay jay@yahoo.com
4 Vaidehi Ahmedabad meera@yahoo.com

In above Student table we apply SELECT Statement for retrieve data.

The SQL SELECT Statement for Student table.

SELECT FROM Student ;

The Result of SQL SELECT query :

ID Name City Email
1 Meera Bombay meera@yahoo.com
2 Ram Surat ram@yahoo.com
3 Jay Bombay jay@yahoo.com
4 Vaidehi Ahmedabad meera@yahoo.com

If we want to retrieve only student name and city from student table then SELECT Statement is :

The SELECT query for retrieve name and city from Student table.

SELECT Name, City  FROM  Student ;

The Result of SQL SELECT query :

Name City
Meera Bombay
Ram Surat
Jay Bombay
Vaidehi Ahmedabad

The SQL SELECT Statement is not case sensitive. The above both SELECT Statements we can be written as :

select * from student ;

select name, city from student ;

We can use some other sql clauses like WHERE, ORDER BY, GROUP BY and HAVING with the SQL SELECT Statement.
In SQL SELECT Statement only SELECT and FROM statement are compulsory. The other clauses where, order by are option.

We can write WHERE, ORDER BY, GROUP BY and HAVING Clauses end of the SQL SELECT query.

We will learn all these clauses in detail in our next sql post. Here we take a simple WHERE clause example with SELECT Statement. We use many arithmetic operator with WHERE clause like ( =, >, >=, <, <=, !=, ..etc).

The Syntax of WHERE in SELECT query

SELECT col1,col2 FROM Table_Name WHERE[Condition];

SELECT col1,col2 FROM Table_Name WHERE column=“value”;
SQL SELECT Query with WHERE Clause Example
SELECT FROM  Student  WHERE ID > 3

The Result of SQL SELECT query is :

ID Name City Email
1 Meera Bombay meera@yahoo.com
2 Ram Surat ram@yahoo.com

I hope you will like this SQL SELECT Statement post…

1 thought on “SELECT Statement in SQL – DML Statements

Leave a Reply

Your email address will not be published. Required fields are marked *