0% found this document useful (0 votes)
4 views

4. SQL - Data Query Language Upto Normal Operators

ARC Technologies & Institutions offers training in software development and testing, focusing on Data Query Language (DQL) concepts such as SELECT, PROJECTION, SELECTION, and JOINS. The document includes various SQL query examples and explanations for retrieving data from employee and department tables. It also covers the use of DISTINCT to avoid duplicate records and ALIAS for renaming columns in query results.

Uploaded by

Suyog Igave
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

4. SQL - Data Query Language Upto Normal Operators

ARC Technologies & Institutions offers training in software development and testing, focusing on Data Query Language (DQL) concepts such as SELECT, PROJECTION, SELECTION, and JOINS. The document includes various SQL query examples and explanations for retrieving data from employee and department tables. It also covers the use of DISTINCT to avoid duplicate records and ALIAS for renaming columns in query results.

Uploaded by

Suyog Igave
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 18

ARC Technologies & Institutions

Software Development And Software Testing Training with Placements Institute

WELCOME TO
SQL SESSION
Address

ARC Technologies and Institute ,NIRMAN ALTIUS, 1,


Mundhwa - Kharadi Rd, behind RADISSON BLU,
Pandhari Nagar, Kharadi, Pune, Maharashtra 411014
9606060871 / 9606060872
ARC Technologies & Institutions DATA QUERY LANGUAGE

SELECT
PROJECTION
SELECTION
JOINS

9606060871 / 9606060872
ARC Technologies & Institutions DATA QUERY LANGUAGE

DATA QUERY LANGUAGE(DQL):


1) SELECT : This Statement Is Used To Retrieving the Data From The Table Which Is Present In Database.

2) PROJECTION : Retrieval Of The Data From The Table By Selecting Column Name Is Known As Projection.

By Default In Projection All The Records Will Get Selected.

3) SELECTION : Retrieval Of Data From The Table By Selecting Column Name As Well As Row Name Is Known As Selection.

4) JOINS : Retrieval Of The Data From The Multiple Tables Simultaneously Is Known As Joins

Syntax For Projection: SELECT * / [DISTINCT] COLUMN_NAME/EXPRESSION[ALIAS]


FROM TABLE_NAME;
1) FROM CLAUSE: Always FROM Clause Will Execute First.
We Can Pass Table Name As An Argument To The FROM Clause.
Function Of FROM Clause:
It Goes The Database Search For The Table Name And Put It Under Execution Area(RAM).
2)SELECT CLAUSE:
Select Clause Will Execute After The Execution Of FROM Clause.
We Can Pass * Or Column Name Or Expression As An Argument.
Function Of Select Clause:
1) It Goes The Table Which Is Under Execution Area From That Table Select The Data And Display The Output.
2) Select Clause Is Responsible For Displaying The Output.
9606060871 / 9606060872
ARC Technologies & Institutions SELECT

EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO

7369 SMITH CLERK 7902 17-Dec-1980 800 20

7499 ALLEN SALESMAN 7698 20-Feb-1981 1600 300 30

7521 WARD SALESMAN 7698 22-Feb-1981 1250 500 30


7566 JONES MANAGER 7839 2-Apr-1981 2975 20

Example 1 : Select Ename from Emp ; Example 2 : Select Ename,MGR from Emp ; Example 3 : Select EMPNO,Ename,SAL from Emp ;

Result : ENAME Result : ENAME MGR Result : EMPNO ENAME SAL

SMITH SMITH 7902 7369 SMITH 800

ALLEN ALLEN 7698 7499 ALLEN 1600

WARD WARD 7698 7521 WARD 1250

JONES JONES 7839 7566 JONES 2975

9606060871 / 9606060872
ARC Technologies & Institutions SELECT

Question 1 : WAQTD All The Employee Name From The Employee Table.
Query : Select Ename
From Employee;

Question 2 : WAQTD All The Salaries From Employee Table.


Query : Select Sal
From Employee;

Question 3 : WAQTD Employee ID Along With Salary.


Query : Select Empno,sal
From Employee;
Question 4 : WAQTD All The Department Number Along With Employee Name From Employee Table.
Query : Select Deptno,ename
From Employee;

Question 5 : WAQTD All The Details Of Employee Table.


Query : Select *
From Employee;
9606060871 / 9606060872
ARC Technologies & Institutions SELECT

Note : * (Asterisk/Wild Character) : it Is Used To Select All The Details From The Given Table
Question 6 : WAQTD All The Department Name From The Department Table.
Query : Select Dname
From Department;
Question 7 : WAQTD Location From Department Table.
Query : Select Location
From Department;

Question 8 : WAQTD All The Details From The Department Table.


Query : Select *
From Department;
Question 9 : WAQTD EMPID Along With Date Of Joining From Employee Table.
Query : Select Empno,hiredate
From Employee;

9606060871 / 9606060872
ARC Technologies & Institutions SELECT

Question 10 : WAQTD All The Department Number Along With Commission From Employee Table.
Query : Select Deptno, comm
From Employee;

Question 11 : WAQTD Designation Along With Salary And Also Display Employee Name.
Query : Select Job, sal, ename
From Employee;

Question 12 : WAQTD All The Employee Names Along With Monthly Salary.
Query : Select Ename, sal
From Employee;
Question 13 : WAQTD Employee Number ,Employee Name , Job Also Salary Along With Annual Salary.
Query : Select Empno, ename, job, sal, sal*12
From Employee;
Expressions

9606060871 / 9606060872
ARC Technologies & Institutions EXPRESSION
Definition : Anything Which Gives Results Or Output Is Known As An Expression

10 + 10 10 / 10

Operand 1 Operand 2 Operand 1 Operand 2

Operators Operators

Note : Operands are of two types


1) Direct Values 2) Immediate Value – It Can be Column Name or Literals
10 * 12 SAL * 12 A*B Where A -> 5 And B -> 5

9606060871 / 9606060872
ARC Technologies & Institutions EXPRESSION

Question 1 : WAQTD Employee Names Along With Midterm Salary.


Query : Select Ename, sal*6
From Employee;

Question 2 : WAQTD Employee Number And Manager Number Along With Annual Commission

Query : Select Empno, mgr, comm*12


From Employee;
Question 3 : WAQTD Employee Names, Along With Monthly Slaary And Also Display 10% Hike To The Salary.

Query : Select Ename, sal, sal+ Sal*10/100


From Employee;
Note : 1%---> 1/100
40%---> 40/100
SALARY =100
100 + 100*10/100==>110
Question 4 : WAQTD Job Along With 22% Deduction In Monthly Salary.

Query : Select Job, sal-sal*22/100


From Employee;
9606060871 / 9606060872
ARC Technologies & Institutions EXPRESSION

Question 5 : WAQTD Employee Name Along With 18% Hike Given To The Monthly Commission But 5% Deduction In Annual Salary.

Query : Select Ename , Comm+comm*18/100,sal*12-sal*12*5/100


From Employee;
Question 6 : WAQTD Monthly Salary Along With 15% Hike Given To Six Month Salary, But 25% Deduction In
Annual Commission.

Query : Select Sal, sal*6*15/100+ Sal*6 ,Comm*12*25/100-comm*12


From Employee;

Question 7 : WAQTD Job, Monthly Salary, Along With 12% Hike Given To Monthly Salary From Employee
Table.

Query : Select Job, sal, sal+sal*12/100


From Employee;

Question 8 : WAQTD Employee Name , Monthly Salary And Annual Salary Also Display 28% Hike Given Annual
Salary.

Query : Select Ename, sal, sal*12, sal*12*28/100+sal*12


From Employee;

9606060871 / 9606060872
ARC Technologies & Institutions ALIAS NAME

Definition : It Is An Alternative Name Given To The Column Name Or An Expression Which Is Present In Resultant Table.

Conditions To Write Alias Name : 1) With Or Without Using The Keyword 'As' We Can Write Alias Name.
2) If We Are Using Multiple Words As Alias Name Than It Has To Be Enclosed It
Within " " Or We Can Join Them Using Underscore( _ ).

Query : Query : Query :


select sal from employee; select sal*12 from employee; select sal*12 Yearly_Sal from employee;
Result : SAL Result : SAL * 12 Result : Yearly_Sal

800 800 800

1600 1600 1600

1250 1250 1250


2975 2975 2975

9606060871 / 9606060872
ARC Technologies & Institutions ALIAS NAME

Question 1 : WAQTD Employee Name And Annual Commission.

Query : Select Ename Name,comm*12 "Annual Commission"


From Employee;

Question 2 : WAQTD Job And Hiredate As Date Of Joining From Employee Table.

Query : Select Job As Designation, Hiredate "Date Of Joining"


From Employee;

Question 3 : WAQTD Employee Name Along With 25% Deduction In Monthly Salary.

Query : Select Ename Name, Sal*25/100-sal Deducted_salary


From Employee;

9606060871 / 9606060872
ARC Technologies & Institutions DISTINCT

Definition : It Is Used To Avoid Duplicate Records Which Are Present In Resultant Table.

Note : 1) Always Distinct Should Be The 1st Argument To The Select Clause.
2) We Can Pass Multiple Argument To The Distinct Clause.
3) Distinct Will Remove The Combination Of Columns Which Are Duplicate.

Query : Select Distinct Deptno Query : Select Distinct Job,deptno Query : Select Distinct Job
From Employee; From Employee; From Employee;
Result : JOB DEPTNO
Result : DEPTNO
CLERK 20 JOB
10 SALESMAN 30 CLERK
20 MANAGER 20
SALESMAN
MANAGER 30
30 MANAGER
MANAGER 10
ANALYST 20 ANALYST
PRESIDENT 10 PRESIDENT
CLERK 30
CLERK 10
9606060871 / 9606060872
ARC Technologies & Institutions DISTINCT

Question 1 : WAQTD Employee Number And Manager Number And Salary With Incentive Of 200.

Query : Select Empno,mgr Manager_number ,Sal+200


From Employee;
Question 2 : WAQTD Name And Sal With Bonus Of 300.

Query : Select Ename, Sal*12+300 Bonus


From Employee;
Question 3 : WAQTD All The Details Of Employee.

Query : Select *
From Employee;
Question 4 : WAQTD All The Details Of Employee Along With Annual Salary.

Query : Select *,Sal*12 Select Emp.*,Sal*12


From Employee; From Employee;
Question 5 : WAQTD All The Details Of Employee Along Annual Salary And Annual Comm.

Query : Select Emp.*,Sal*12,comm*12


From Employee; 9606060871 / 9606060872
ARC Technologies & Institutions SELECTION

Definition : Retrieval Of Data From The Table By Selecting Column Name As Well As Row Name Is Known As Selection.

Syntax : Select */[Distinct] Column_name/Expression[alias]


From Table_name
Where <Filter_condition>;
Note : 1) Where Clause Is Used To Filter The Records.
2) Where Clause Executes Row By Row.
3) After The From Clause Where Clause Will Execute.
4) We Cannot Use Alias Name In Where Clause.
5) We Can Write Multiple Conditions In Where Clause.
Query : Select *
From Employee
Where Ename='smith';
Result :

EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO


7369 SMITH CLERK 7902 17-Dec-1980 800 20

9606060871 / 9606060872
ARC Technologies & Institutions SELECTION

Question 1 : WAQTD Employee Name And Salary Of Employee Where Name Is King.
Query : Select Ename,sal
From Employee
Where Ename='king';
Question 2 : WAQTD Name And Job ,Department Number If Employees Are Working In Dept Number 20.
Query : Select Ename,job,deptno
From Employee
Where Deptno=20;
Question 3 : WAQTD Name And Salary Given To All Employee If Employees Are Getting Salary More Than 1600.
Query : Select Ename,sal
From Employee
Where Sal>1600;

Question 4 : WAQTD All The Details Of Employee Except Who Are Working As Salesman
Query : Select *
From Employee
Where Job!='Salesman';
Note : Not Equal Operator (!=) OR (<>)
9606060871 / 9606060872
ARC Technologies & Institutions SELECTION

Question 5 : WAQTD Employee Number ,Commission Along With Name If Employee Are Getting Comm Less Than 1500.
Query : Select Empno,comm,ename
From Employee
Where Comm<1500;
Question 6 : WAQTD Employee Number ,Salary Of Employee Whose Employee Number Is 7788
Query : Select Empno,sal
From Employee
Where Empno=7788;
Note : Note Equal Operator (!=) OR (<>)
Question 7 : WAQTD Details Of Employee Who Are Not Working In Dept 30.
Query : Select *
From Employee
Where Deptno != 30;

Question 8 : WAQTD All The Details Of Employee Along With Annual Salary Of All The Employee Except Clerk.
Query : Select Emp.*,Sal*12
From Employee
Where Job<>'clerk';
9606060871 / 9606060872
ARC Technologies & Institutions DISTINCT

Question 9 : WAQTD Details Of Employee Who Are Hired After 81.


Query : Select *
From Employee
Where Hiredate > ‘1981-12-31';
Question 10 : WAQTD Name ,Commission And Salary Given To Employee Who Are Getting Salary Lesser Than Commission.
Query : Select Ename, comm, sal
From Employee
Where Sal<comm;
Question 11 : WAQTD Name ,Job And Hiredate Of Employee Who Are Hired Before 87.
Query : Select Ename, job, hiredate
From Employee
Where Hiredate < ‘1987-01-01';
Question 12 :WAQTD Name,job Of Employee Along With Annual Salary If Their Annual Salary Is More Than 20k.
Query : Select Ename, job, sal*12 Annual_salary
From Employee
Where sal*12>20000;
Question 13 :Waqtd Details Of Employees Who Are Working As Salesman In Dept Number 30.

9606060871 / 9606060872

You might also like