0% found this document useful (0 votes)
14 views4 pages

SQL - SELECT - WHERE

Uploaded by

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

SQL - SELECT - WHERE

Uploaded by

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

--Delete: It is used to remove data from table with condition or without condition

--It removes row by row so it degrades performance.


--If requirment demands to remove based on condition, then use DELETE
--If table is having IDENTITY column, then value will not set to zero

--Truncate: It is used to remove data from the table without condition


--It removes all data at one short so it improves performance.
--It will be used when you implement Full Loading in ETL's
--If table is having IDENTITY column, then value will set to zero

--DQL(Data Querying Language)


------------------------------
--It is used to read data from table(s)
--syn:
SELECT
*/<list Of Columns>
FROM <tableName>
WHERE <condition>
GROUP BY <list Of Columns>
HAVING <condition>
ORDER BY <list Of Columns>

USE DATASTORE

--Write a SQL stattemet to read data from table for all columns
SELECT *
FROM employee

--Write a SQL code to read data form table with specific columns
SELECT
EmployeeNo,
Ename,
Job,
DepartmentNo,
Salary
FROM employee

--Write a SQL statement to read data from employee if the employees are woring in
department number 10
--WHERE: It is used to restrict the data based on on condition
--Condition always returns TRUE or FALSE
--We can frame the condition by using the following syntax
--syn: columnName<operator>value

SELECT *
FROM employee
WHERE DepartmentNo=10

--Write a SQL Statement to read data from employee, if the employees are getting more
than 2000 salary
SELECT *
FROM employee
WHERE Salary>2000

--Write a SQL Statement to read data from employee, if the employees are getting less
than 2000 salary
SELECT *
FROM employee
WHERE Salary<2000
--Wriate SQL Statement to get employee details, if the employees working in Department
10 or Department 20
SELECT *
FROM employee
WHERE DepartmentNo=10 OR DepartmentNo=20

/*

To join multiple conditions, then we have to use Logical OR operator or Logical AND
operator
Syn: Condition-1 OR/AND Condition-2

Logical OR: If business requirement demands to satisfy either one of the condition,
then we can use Logical OR operator
Logical AND: If business requirement demands to satisfy both of the conditions, then
we can use Logical AND operator

*/

--Write a SQL statement to get employee details, if the employee are working as
Salesman or working in department 20
--Note: Strings will be enclosed in single(') quotes
SELECT *
FROM employee
WHERE Job='Salesman' OR DepartmentNo=20

--Write a SQL Statement to get employee details, if the employee are getting less than
2000 in the department 30
SELECT *
FROM employee
WHERE Salary<2000 AND DepartmentNo=30

--Write a SQL Statement to get employee details if the employees are getting Salary
from 2000 to 3000
SELECT *
FROM employee
WHERE Salary>=2000 AND Salary<=3000

SELECT *
FROM employee
WHERE Salary BETWEEN 2000 AND 3000

--Wriate SQL Statement to bring data from employee, if the employees are join in 2023-
04-02 date
SELECT *
FROM employee
WHERE Hiredate = '2023-04-02'

--Write a SQL statement to bring data from employee, if the employees are joined in
the year of 2023
SELECT *
FROM employee
WHERE Hiredate >= '01-01-2023' AND Hiredate<='12-31-2023'
--Write a SQL Statement to bring data employee if the employees are joined in the
month of September 2023

--Write a SQL Statement to bring employee data if the employees are not joined in the
month of September 2023

--Write a SQL Statement to bring employee details if the employees are not eligible
for commission
SELECT *
FROM employee
WHERE Commission IS NULL

/*
******************************************************************
Functions
******************************************************************
Functions are used to handle Numbers, Text and Date and Time
There are few categories of the Functions
1. Numeric Functions
2. String Functions
3. Date & Time Functions
4. Aggregate Functions
5. Windows Functions

Numeric Functions:
1. ABS(<Number>): Returns the absolute value of a number
*/

--Write a SQL Statement to get absolute value of given number


SELECT
ABS(10) AS Abs1,
ABS(-10) AS Abs2,
ABS(0) AS Abs3

--Write a SQL Statement to deduct 2000 from everyone's salary


SELECT
EmployeeNo,
Ename,
Salary,
Salary-2000 AS SalaryMinus2000
FROM employee

--Write a SQL Statement to apply ABS operation on SalaryMinus2000 calculation


SELECT
EmployeeNo,
Ename,
Salary,
Salary-2000 AS SalaryMinus2000,
ABS(Salary-2000) AS AsbSalaryMinus2000
FROM employee

/*
ROUND(<Number>, <No: Of Decimal Places>) : It is used to round a number to a specified
number of decimal places.

No:Of Decimal Places


1. If it is +ve Number, then it rounds decimal number
2. If it is -ve Number, then it rounds main number

Ex: 10.5
10--> Main Number
.5--> Decimal Number

*/

SELECT 1/2.0

--Write a SQL Statement to apply division operation Salary with 3.5


SELECT
EmployeeNo,
Ename,
Job,
Salary,
Salary/3.5 AS NewSalary
FROM employee

--Apply round operation with 2 decimal places for above Query

SELECT
EmployeeNo,
Ename,
Job,
Salary,
Salary/3.5 AS NewSalary,
ROUND(Salary/3.5, 2) AS RundedSalary
FROM employee

You might also like