What IS SQL?
SQL Stands for Structured Query Language.
Structured = In a Processed Way,Proper Methodical Approach
Query = Asking Questions
Language = Mode / Medium of Communication
So SQL = Structured + Query + Language
= (In a Processed Way, Proper Methodical Approach) + (Asking Questions) + (Mode / Medium of Communication)
After a rearrangement if we try to construct a line it could be:
Mode / Medium of Communication Via Asking Questions
- Mode / Medium of Asking Questions in a proper methodical approach.
Out of the above two the option 2 sounds better hence I will choose 2.
So SQL now stands for Mode / Medium of Asking Questions in a proper methodical approach.
Now this brings us to the next question.
Asking Questions . But Questions are asked by some-one (Individual 1) to Some-One (Individual 2)
So in SQL WHO Asks the Question and To WHOM
WHO = Business / Business User / Technical Consultant
WHOM = Database / ERP System / Any system Holding Data / Datawarehouse
So we come to conclusion that via SQL
Business / Business User / Technical Consultant asks questions to Data Storing System (Commonly referred to as Database) in a proper methodical way (following specific syntax)
Graphical Representation
Database Table:
The above data gets stored into the Database in a Structure Called Table and it looks like as shown below :
Database Column
Each Database Table is made up of one or more vertical rows typically referred to as Columns.
In the above example we have following columns
- Employee No
- Employee Name
- Position
- Department
SQL Example
Say a Technical Consultant Adam has been asked by CEO of ABC Company to give him the details of all employees . The Output would be fetched via a SQL.
Sql Syntax
So if we want to get the data of all employees we will have a SQL like :
Sql 1 : Get All Data
SELECT * FROM EMPLOYEES; ---------------------------------------------------------------------------- (a)
OR
SELECT ALL FROM EMPLOYEES;------------------------------------------------------------------------( b )
OR
SELECT EMPLOYEE_NO,
EMPLOYEE_NAME,
POSITION,
DEPARTMENT
FROM EMPLOYEES; -------------------------------------------------------------------------------------- ( c )
OR
SELECT E.ALL FROM EMPLOYEES E; ------------------------------------------------------------------( d )
OR
SELECT E.* FROM EMPLOYEES E ; ------------------ ( e )
OR
SELECT E.EMPLOYEE_NO as “Employee No”,
E.EMPLOYEE_NAME as “Employee Name”,
E.POSITION as “Position”,
E.DEPARTMENT as “Department”
FROM EMPLOYEES E ----------------------------------------- ( f )
Note :- Here in ( c ) we have used ‘E’ for ‘Employees’ which is an alias. Like we have Names (Dinesh) and pet-name (Dinu). So we can refer the to the TABLE with either Real Name ( Employees ) or with Pet-Name ( E )
WHERE CLAUSE
Whenever we want to Restrict Data in SQL we need to use where clause. In this example we have 3 department while we are interested to get data for ABC Sales so SQL will be :
SQL 2 : SQL with Where Clause
SELECT * FROM EMPLOYEES WHERE DEPARTMENT = ‘ABC Sales’; ------------------------------------------------------------- (a)
OR
SELECT ALL FROM EMPLOYEES WHERE DEPARTMENT = ‘ABC Sales’;------------------------------------------------------------( b )
OR
SELECT EMPLOYEE_NO,
EMPLOYEE_NAME,
POSITION,
DEPARTMENT
FROM EMPLOYEES
WHERE DEPARTMENT = ‘ABC Sales’; ------------------------------------------------------------------------------------------------------- ( c )
OR
SELECT E.ALL FROM EMPLOYEES E WHERE DEPARTMENT = ‘ABC Sales’------------------------------------------------------ ( d )
OR
SELECT E.* FROM EMPLOYEES E WHERE E.DEPARTMENT = ‘ABC Sales’ ; ------------------ ( e )
OR
SELECT E.EMPLOYEE_NO as “Employee No”,
E.EMPLOYEE_NAME as “Employee Name”,
E.POSITION as “Position”,
E.DEPARTMENT as “Department”
FROM EMPLOYEES E
WHERE E.DEPARTMENT = ‘ABC Sales’ ----------------------------------------- ( f )