Data Query Language (Part 1)
An Introduction to SQL Statements and the Basics of Projection
Overview of SQL statements:
Sql statements are classified into 5 types-
Data Definition Language
Data Manipulation Language
Transaction Control Language
Data Control Language
Data Query Language
Data Query Language
Data Query Language is used to fetch the data from the database
It has 4 statements:-
Select
It is a process of fetching/retrieving the data from the table and display it.
Projection
It is a process of fetching/retrieving the data from the table by selecting only the columns
In projection all the values present in a particular column are selected by default
Selection
It is a process of fetching/retrieving the data from the table by selecting both rows and columns
Joins
It is a process of retrieving/fetching the data from the multiple tables simultaneously.
Projection
It is a process of fetching/retrieving the data from the table by selecting only the columns
In projection all the values present in a particular column are selected by default
Syntax -
SELECT * / [DISTINCT] COL_NAME/ EXPRESSION [ALIAS]
FROM TABLE_NAME;
Order of execution -
FROM CLAUSE
SELECT CLAUSE
In this example I have considered a table EMP which has ENAME column in it. I used Projection statement to extract that particular column from EMP table from the database and display the result table.
Working of Projection statement
FROM CLAUSE is executed first.
In FROM CLAUSE we can pass table_name as an argument
The job of FROM CLAUSE is to go to the database, search for the table and put that table under execution.
After the execution of the FROM CLAUSE, SELECT CLAUSE will execute.
In SELECT CLAUSE, we can pass three arguments
*
COL_NAME
EXPRESSION
The job of SELECT CLAUSE is to go to the table which is under execution and select the column which we mention.
SELECT CLAUSE is responsible for the result table.