Stands For Structured Query Language: - Accepted As Standard Language (ISO, ANSI) For Relational Database

Download as pdf or txt
Download as pdf or txt
You are on page 1of 123

SQL

• Stands for Structured Query Language


• Accepted as Standard Language(ISO,ANSI)
for Relational database
• Non Procedural Language
(what should be done/not how it should be done)
• Interface used to access data from database
SQL Statements

SELECT Data retrieval


INSERT
UPDATE Data manipulation language (DML)
DELETE
MERGE

CREATE
ALTER Data definition language (DDL)
DROP
RENAME
TRUNCATE

COMMIT Transaction control


ROLLBACK
SAVEPOINT

GRANT Data control language (DCL)


REVOKE
SELECT command query

Syntax : SELECT (column_list )


FROM (table_list )
WHERE (row restriction)
GROUP BY (attribute names)
HAVING (group restriction)
ORDER BY (attribute name or names)
Commands
1. To Create Table
Create Table Tablename
(
field Name DataType (Size)
)
2. To Display The Content Of Table
Select * From Tablename;

3. To Display Structure Of Table


Desc Tablename;

4.To Display All Tables (For Current User)


Select * From Tab;
TOOLS FOR SQL

1.SQL * PLUS

2. SQL WORK SHEET


3. TOAD
4. SQL DEVELOPER
5. ENTERPRISE MANAGER
SQL
COMMANDS DATA CASE
NOT CASE SENSITIVE
SENSITIVE

SQL

STRING,DATE
DATATYPES CLAUSES ARE
SHOULD BE ENTERED IN
ENCLOSED IN DIFFERENT LINES
SINGLE QUOTES
SELECTING ALL COLUMNS
P
ALL COLUMNS
SELECT *
FROM P
VID PID VID PID
V1 P10 V1 P10
V1 P8 V1 P8
ALL
V2 P5 V2 P5 COLUMNS
V3 P8 V3 P8
SELECT-PROJECTION
P
PROJECTION
SELECT VID
VID PID FROM P
VID
V1 P10
V1
V1 P8
V2
V2 P5
V2
V3 P8
V3
SELECT-RESTRICTION
P
RESTRICTION
SELECT *
FROM P
VID PID WHERE
VID PID
V1 P10 VID=‘V1’
V1 P10
V1 P8
V2 P5
V3 P8
Limiting Rows Using a Selection
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
7369 SMITH CLERK 7902 17-DEC-80 800 20
7499 ALLEN SALESMAN 7698 20-FEB-81 1600 300 30
7521 WARD SALESMAN 7698 22-FEB-81 1250 500 30
7566 JONES MANAGER 7839 02-APR-81 2975 20
7654 MARTIN SALESMAN 7698 28-SEP-81 1250 1400 30
7698 BLAKE MANAGER 7839 01-MAY-81 2850 30
7782 CLARKE MANAGER 7839 09-JUN-81 2450 10
7788 SCOTT ANALYST 7566 19-APR-87 3000 20
7839 KING PRESIDENT 17-NOV-81 5000 10
7844 TURNER SALESMAN 7698 08-SEP-81 1500 30
7876 ADAMS CLERK 7788 23-MAY-87 1100 20
7900 JAMES CLERK 7698 03-DEC-81 950 30
7902 FORD ANALYST 7566 03-DEC-81 3000 20
7934 MILLER CLERK 7682 23-JAN-82 1300 10

“retrieve all employees in department 10”

EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO


7934 MILLER CLERK 7682 20-FEB-81 1300 10
7839 KING PRESIDENT 20-FEB-81 5000 10
7782 CLARKE MANAGER 7839 20-FEB-81 2450 10
WHERE CLAUSE

compare values in columns, literal, arithmetic expressions, or functions

•COLUMN NAME
•COMPARISON CONDITION

• Column name, constant, or list of values


OPERATORS USED WITH WHERE

OPERATOR OPERATOR
TYPE
COMPARISON =,<=,>=,<>
LOGICAL AND,OR,NOT
SPECIAL IN,NOT IN ,BETWEEN
PATTERN LIKE,NOT LIKE
MATCHING
NULL IS NULL,IS NOT
NULL
Pattern Matching(Like operator)

COMMAND DESCRIPTION

S% BEGIN WITH S

%S END WITH S
SECOND LETTER STARTING
_S%
WITH S
_____ EXACTLY 5 LETTERS
PRACTICE SESSIONS-1

1. List the employees belonging to the department 20:


2. List the name and salary of the employees whose
salary is more than 1000:
3. List the employee number and name of managers:
4. List the names of the clerks working in the
department 20:
5. List the names of analysts and salesmen
6. List the details of the employees who have joined
before the end of September- 81:
7. List the names of employees who are not managers:
8. List the name of the employees whose employee
numbers are 7369, 7521, 7839, 7934, 7788:
9. List the department number of Sales and Research
departments
PRACTICE SESSIONS-2
1. List the employee details not belonging to the department 20 and 30:
2. List the employee name and salary, whose salary is between 1000 and
2000:
3. List employee names, who have joined before 30th June-81 and after
December-81:
4. Display the name, job, and salary for all employees whose jobs are either
salesman or clerk and whose salaries are not equal to 1,500,2,000 ,
3,000.
5. Find the employees who have joined in February
6. Find the employees who have joined in 1981 and enames does not have
‘S’
7. Find enames who have not joined in december or february
8. Find employees who have ‘A’ as starting character and ‘S’ as end
character.
9. Find employees who have ‘S’ in their name and job is other than ‘CLERK’
Working with NULL values

• NULL values are not 0 or a blank.

• It represents an unknown or inapplicable value

• It cannot be compared using the relational and/or logical


operators

• The special operator 'IS' is used with the keyword 'NULL' to


locate NULL values
Examples:

 List the employee names, who are not eligible for


commission:

SELECT ename FROM emp


WHERE comm IS NULL;
PRACTICE SESSIONS

1. List the employee names, who are not eligible


for commission:
2. List the name of the employee and designation
(job)of the employee, who does not report to
anybody (mangers is NULL)
3. List the employees who are eligible for
commission:
4. List the details of employees, whose salary is
greater than 2000 and commission is null
5. List the details of employees who does not have
managers.
COLUMN ALIASING

TO CHANGE DISPLAY HEADINGS

SELECT ENAME,SAL,(SAL+100) “ newsal”,(SAL+100) as newsal,


(SAL+100) newsal
FROM EMP
WHERE ENAME=‘SMITH’

ENAME SAL newsal NEWSAL NEWSAL


--------------- ---------- ------------- --------------- ---------------
SMITH 800 900 900 900
DISTINCT
TO ELIMINATE DUPLICATES

SELECT JOB FROM EMP SELECT DISTINCT(JOB) FROM EMP

JOB
---------
CLERK
SALESMAN
SALESMAN JOB
MANAGER ---------
SALESMAN ANALYST
MANAGER CLERK
MANAGER PRESIDENT
ANALYST MANAGER
PRESIDENT SALESMAN
SALESMAN
CLERK
CLERK
ANALYST
CLERK
CONCAT OPERATOR
select ‘RAM’||’LAKHAN’ “CONCAT” FROM DUAL
CONCATS STRINGS OR
COLUMNS CONCAT
-------------------------------
|| IS THE NOTATION RAMLAKHAN

SELECT ENAME||’ is working as ‘|| JOB FROM EMP


SMITH is working as CLERK
ALLEN is working as SALESMAN
WARD is working as SALESMAN
JONES is working as MANAGER
MARTIN is working as SALESMAN
BLAKE is working as MANAGER
CLARK is working as MANAGER
SCOTT is working as ANALYST
KING is working as PRESIDENT
TURNER is working as SALESMAN
ADAMS is working as CLERK
JAMES is working as CLERK
FORD is working as ANALYST
MILLER is working as CLERK
q OPERATOR
INCREASES READABILITY AND USABILITY

SELECT ‘DOMINO’||q’[‘s]’ ||’PIZZA’ from dual

DOMINO’s PIZZA
DEFINE/UNDEFINE
DEFINE- DEFINES A VARIABLE AND ASSIGNS A VALUE TO IT

DEFINE V_SAL=5000

SELECT ENAME,SAL FROM EMP WHERE SAL=&V_SAL

ENAME SAL
---------- ----------
KING 5000 UNDEFINE- REMOVES VARIABLE

UNDEFINE V_SAL

SELECT ENAME,SAL FROM EMP WHERE SAL=&V_SAL

Enter value for v_sal: 3000


ENAME SAL
---------- ----------
SCOTT 3000
FORD 3000
Order by Clause
• SQL uses the ORDER BY clause to impose an order on the
result of a query.
• ORDER BY clause is used with SELECT statement
• The syntax is
SELECT[DISTINCT] <column list> | <expr>
FROM <table>[,<table>] [WHERE condition]
[ORDER BY <columns>] [ASC|DESC]
• One or more columns and/or expressions can be specified in
ORDER BY clause.
Examples:
 List the empno, ename, sal in ascending order of salary:
SELECT empno, ename, sal FROM emp
ORDER BY sal;
Order by Clause
SELECT ENAME,SAL FROM EMP
•COLUMN NAME
ORDER BY ENAME
•COLUMN NUMBER
•ALIAS
SELECT ENAME,SAL,HIREDATE "JOINDATE"
SELECT ENAME,SAL FROM EMP FROM EMP
ORDER BY 2 ORDER BY "JOINDATE"
ENAME SAL
---------- ----------
ADAMS 1100
ALLEN 1600
ENAME SAL JOINDATE
BLAKE 2850
ENAME SAL ---------- ---------- ------------------
CLARK 2450
---------- ---------- SMITH 800 17-DEC-80
FORD 3000
SMITH 800 ALLEN 1600 20-FEB-81
JAMES 950
JAMES 950 WARD 1250 22-FEB-81
JONES 2975
ADAMS 1100 JONES 2975 02-APR-81
KING 5000
WARD 1250 BLAKE 2850 01-MAY-81
MARTIN 1250
MARTIN 1250 CLARK 2450 09-JUN-81
MILLER 1300
MILLER 1300 TURNER 1500 08-SEP-81
SCOTT 3000
TURNER 1500 MARTIN 1250 28-SEP-81
SMITH 800
ALLEN 1600 KING 5000 17-NOV-81
TURNER 1500
CLARK 2450 JAMES 950 03-DEC-81
WARD 1250
BLAKE 2850 FORD 3000 03-DEC-81
JONES 2975 MILL 1300 23-JAN-82
SCOTT 3000 SCOTT 3000 19-APR-87
FORD 3000 ADAMS 1100 23-MAY-87
KING 5000
PRACTICE SESSIONS

1. List the empno, ename, sal in ascending order of salary:


2. List the employee name and hiredate in descending
order of hiredate:
3. List the employee name, salary, Job and Department no
descending order of Department No and salary:
4. List the employee details in ascending order of salary:
(using column nos.,)
5. List the employee name, salary, PF, HRA, DA and
gross; order the result in ascending order of gross. HRA
is 50% of salary and DA is 30 % of salary.
SQL FUNCTIONS

– Functions are a very powerful feature of SQL


and can be used to do the following:
• Perform calculations on data
• Modify individual data items
• Manipulate output for groups of rows
• Format dates and numbers for display
• Convert column data types
– SQL functions sometimes take arguments
and always return a value.
TWO TYPES OF SQL FUNCTIONS

Functions

Single-row Multiple-row
functions functions

Operate on single Can manipulate groups


rows only and return of rows to give one
one result per row. result per group of rows
(group functions)
Single-Row Functions

Character

Accepts
Number
different types Single-row
functions

Conversion Date
Character Functions

Character
functions

Case-manipulation Character-manipulation
functions functions
LOWER CONCAT
UPPER SUBSTR
INITCAP LENGTH
INSTR
LPAD | RPAD
TRIM
REPLACE
TRANSLATE
Case Manipulation Functions

These functions convert case for character


strings.
Function Result
LOWER('SQL Course') sql course
UPPER('SQL Course') SQL COURSE
INITCAP(‘sql course') Sql Course
Character-Manipulation Functions

These functions manipulate character strings:


Function Result
CONCAT('Hello', 'World') HelloWorld
SUBSTR('HelloWorld',1,5) Hello
LENGTH('HelloWorld') 10
INSTR('HelloWorld', 'W') 6
LPAD(salary,10,'*') *****24000
RPAD(salary, 10, '*') 24000*****
TRIM('H' FROM 'HelloWorld') elloWorld
REPLACE(‘HELLO’,’EL’,’12’) H12LO
TRANSLATE(‘HELLO’,’EL’,’12’) H122O
Character-Manipulation Functions

select trim(' this string has leading and


trailing spaces ‘)
from dual;

TRIM('THISSTRINGHASLEADINGANDTR
AILINGSPACES
-------------------------------------------
this string has leading and trailing spaces
PRACTICE SESSIONS
1. Display the total content of dept table & salgrade
table.
2. List the employees whose names start with "S“
(not "s")
3. List the employee names ending with "S“.
4. List the names of employees whose names have
exactly 6 characters:
5. List the employee names having "I" as the second
character: (Write minimum 2 queries)
6. Display o/p ‘SMITH works as CLERK’ using concat()
7. Find number of ‘A’ occurrences in each row of
dname column
PRACTICE SESSIONS
8. Write a query to perform trim operation on ename column
of emp table.
9. Write a query to perform ‘replace’ function on ename for
replacing first 3 characters of ename by numbers.
10. Left justify sal column of emp table.(use #)
11. Right justify job column of emp table (use $)
12. Write a query to find 3rd character in ename.
13. Create a query to display all the data from the
EMPLOYEES table. Separate each column by a
comma. Name the column THE_OUTPUT.
14. Write a query to find last character in ename.
15. Display all enames with only 3rd character replaced by
numbers.
16. Display all enames with last character being different
case.
17. Display only those names where last character is getting
repeated.
PRACTICE SESSIONS
18. Display only those names where second character is getting
repeated In 3rd position.

19. Display all the employees names replacing with * as per the
length of their names.

20. Show those employees that have a name starting with ‘J’,
‘K’,’M’,’S’

21. Display the names of all employees who have both an A and
an E in their name.(use other than like operator)

22. Display the name concatenated with the job , separated by a


comma and space, and name the column Employee and Title.

23. Display all employee names in which the third letter of the
name is A.
PRACTICE SESSIONS
24. Find all the names where 3rd character is getting
repeated.

25. Find all the enames where 3rd character is a VOWEL.

26. Display all the enames with last character being lower
case.

27. Display all the enames with first character being lower
case.

28. Find the jobs where character ‘A’ is getting repeated.


Number Functions
•ROUND()
•TRUNC()
•CEIL()
•FLOOR()
•ASCII()
•CHR()
•SIGN()
•MOD()
•ABS()
Number Functions
MOD
SQL> SELECT MOD(9,2) FROM DUAL;

MOD(9,2)
----------------
1

SIGN FUNCTION RESULT

SQL> SELECT SIGN(&A-&B) FROM DUAL; A>B 1


Enter value for a: 10 A<B -1
Enter value for b: 20 A=B 0
SIGN(10-20)
-----------------------
-1
Number Functions
ASCII
SQL> SELECT ASCII('A') FROM DUAL;

ASCII('A')
----------
65

CHR
SQL> SELECT CHR(65) FROM DUAL;

CHR(65)
--------------------
A
ABS SQL> SELECT ABS(-75) FROM DUAL;

ABS(-75)
----------
75
Number Functions
ROUND
SQL> SELECT ROUND(99.526,2) FROM DUAL;
ROUND(99.526,2)
-----------------------
99.53

TRUNC
SQL> SELECT TRUNC(99.526,2) FROM DUAL;
TRUNC(99.526,2)
-----------------------
99.52
CEIL & FLOOR
SQL> SELECT CEIL(99.4) ,FLOOR(99.4) FROM DUAL;
CEIL(99.4) FLOOR(99.4)
---------------- -------------------
100 99
Date Functions

Function Description
MONTHS_BETWEEN Number of months
between two dates
ADD_MONTHS Add calendar months to
date
NEXT_DAY Next day of the date
specified

LAST_DAY Last day of the month

ROUND Round date

TRUNC Truncate date


Using Date Functions

• MONTHS_BETWEEN ('01-SEP-95','11-JAN-94')
19.6774194

• ADD_MONTHS ('11-JAN-94',6) '11-JUL-94'

• NEXT_DAY ('01-SEP-95','FRIDAY')
'08-SEP-95'

• LAST_DAY('01-FEB-95') '28-FEB-95'

• ROUND(TO_DATE('01-JUL-05'),’YYYY’)
‘01-JAN-06'
• TRUNC(TO_DATE('01-JUL-05'),’YYYY’)
‘01-JAN-05'
CONVERSION FUNCTIONS
•TO_CHAR
•TO_DATE
•TO_TIMESTAMP
•TO_YMINTERVAL
•TO_DSINTERVAL
•TO_NUMBER
Useful formats while Using To_char
Function
FORMAT DESCRIPTION EXAMPLE
MM Number of month 12
RM Roman Numerical month XII
MON Three letter abbreviation DEC
MONTH Month fully spelt out DECEMBER
DDD Number of days since Jan 1 347
DD Number of the day of month 13
D Number of days in week 2
DY Three-letter abbreviation of day WED
DAY Day fully spelt out WEDNESDAY
YYYY Full 4 digit year 1995
SYYYY Signed Year 1000,BC=1000
YYY Last three digits of year 995
YY Last 2 digits of year 95
Y Last digit of year 5
YEAR Year fully spelt out NINTEEN-NINTY-FIVE
GENERAL FUNCTIONS

Function syntax Logic equivalent


NULLIF(E1, E2) IF E1 = E2 THEN NULL ELSE E1
NVL(E1, E2) IF E1 IS NULL THEN E2 ELSE E1
NVL2(E1, E2, E3) IF E1 IS NULL THEN E3 ELSE E2
IF E1 IS NULL E2 ELSIF E1 IS
COALESCE(E1,E2,E3) NOT NULL E1 ELSIF (E1,E2) NULL
E3
DECODE

SELECT ,ENAME,SAL,
DECODE(JOB,'CLERK',2.0*SAL,'ANALYST',2.25*SAL,'SALESMAN',2.5*SAL,SAL)
"BONUS“ FROM EMP

ENAME JOB SAL BONUS


---------- -----------------------------------------------
SCOTT ANALYST 3000 6750
FORD ANALYST 3000 6750
MILLER CLERK 1300 2600
JAMES CLERK 950 1900
SMITH CLERK 800 1600
ADAMS CLERK 1100 2200
BLAKE MANAGER 2850 2850
JONES MANAGER 2975 2975
CLARK MANAGER 2450 2450
KING PRESIDENT 5000 5000
TURNER SALESMAN 1500 3750
MARTIN SALESMAN 1250 3125
WARD SALESMAN 1250 3125
ALLEN SALESMAN 1600 4000
CASE STATEMENT
SELECT ENAME,SAL,JOB,
CASE WHEN JOB=‘CLERK’ THEN 2.*SAL
WHEN Job=‘SALESMAN’ THEN 2.5*sal,
WHEN Job=‘ANALYST’ THEN 2.25*sal
ELSE
SAL) “BONUS” FROM EMP

ENAME JOB SAL BONUS


---------- -----------------------------------------------
SCOTT ANALYST 3000 6750
FORD ANALYST 3000 6750
MILLER CLERK 1300 2600
JAMES CLERK 950 1900
SMITH CLERK 800 1600
ADAMS CLERK 1100 2200
BLAKE MANAGER 2850 2850
JONES MANAGER 2975 2975
CLARK MANAGER 2450 2450
KING PRESIDENT 5000 5000
TURNER SALESMAN 1500 3750
MARTIN SALESMAN 1250 3125
WARD SALESMAN 1250 3125
ALLEN SALESMAN 1600 4000
PRACTICE SESSIONS

1. Select To-day’s date.


2. Find out the experience of each employee and arrange in the
increasing order of experience.
3. Select a query to return next Sunday.
4. Write a query to find how old are you?( express in years and
months)
5. List employees hired on Monday.
6. Show all employees who were hired in the first half of the month
(before the 16th of the month).
7. Write a Query to find out the last day of any given year.
8. Add 1 year to each employee and display as a separate column.
9. Write a query to find first Sunday of hiredate. (first Sunday in the
joining month)
10. Create an anniversary overview based on the hire date of the
employees. Sort the anniversaries in ascending order.
PRACTICE SESSIONS

11. List employees having experience greater than 200 months.


12. Declare certain percentage of bonus based grades.
13. Display each employee’s last name, hire date, and salary review
date, which is the first Monday after six months of service. Label the
column REVIEW. Format the dates to appear in the format similar
to “Monday, the Thirty-First of July, 2000.”
14. Print list of employees displaying “Good salary” if sal > 3000,
“Average salary” if sal=3000 and “Poor salary” if sal < 3000.
15. Write a query which returns the DAY of the week for any date
entered in the format dd.mm.yy
16. Write a query to calculate the length of any employee has been with
the company. Display in number of years and months.
17. Display name, hire date, and day of the week on which the
employee started. Label the column DAY. Order the results by the
day of the week starting with Monday.
17a. Find the details of employee whose joining date is in 4th quarter and
day is ‘Wednesday’
PRACTICE SESSIONS

18. Employees will be given an additional incentive for completing one year
service. Who have joined on or before 15th will be paid on the last Friday of
the same month after a year of appointment and who have joined after 15th
will be paid on last Friday of next month after a year. Display their incentive
payment date.
19. List employees hired on Monday.
20. Calculate how many days old you are.
21. Write a query that produces the following for each employee:
<employee name> earns <sal> monthly but wants <3 times salary>.
Label the column Dream Salaries.
22. Create a query that displays the employees names and commission
amounts. If an employee does not earn commission, put “No Commission.”
Label the column COMM.
23. Write a query to find out first ‘Sunday’ of hiredate
24. Create an anniversary overview based on the hire date of the employees.
Sort the anniversaries in ascending order.
25. Display the name and hire date of every employee who was hired in 1981.
Aggregate Functions
MIN(SAL)

29025/14 AVG(SAL)

COUNT(*)

MAX(SAL)

SUM(SAL)
Aggregate Functions
COUNT(*) DATE
CHARACTER
MIN NUMERIC
MAX
AVG NUMERIC
SUM

GROUP BY TO GROUP RESULTS

HAVING TO RESTRICT
GROUPS
COUNT
SELECT COUNT(*) FROM EMP

SELECT COUNT(COMM) FROM EMP

SELECT COUNT(HIREDATE) FROM EMP


Aggregate Functions
The aggregate functions produce a single value for an entire
group or table

• COUNT determines the number of rows or non NULL


column values

• SUM determines the sum of all selected columns

• MAX : determines the largest of all selected values of a


column

• MIN : determines the smallest of all selected values of a


column

• AVG : determines the average of all selected values of a


column

• In all the above functions, NULLs are ignored


PRACTICE SESSIONS
1. List the number of employees working with the company
2. List the number of jobs available in the emp table:
3. List the total salaries payable to employees
4. List the maximum salary of employee working as a salesman:
5. List the minimum salary from emp table
6. List the average salary and number of employees working in the
department 20:
7. Count the number of people who joined in the leap year.
8. Find out the number of people having vowels as a last character
in their enames
9. Find the number of people who have S in their names.
10. Find out the total salary given to employees who have joined after
22-feb-81
11. Find out total salary given to deptno 10 ,20
Group by and Having Clause

• The GROUP BY clause is used to divide the rows in a table


into smaller groups

• The GROUP BY clause is used with SELECT clause

• SQL groups the result after it retrieves the rows from a table

• Conditional retrieval of rows from a grouped result is possible


with the HAVING clause

• The syntax for GROUP BY clause is


SELECT[DISTINCT] <column list> | <expr>
FROM <table>[,<table>] [WHERE condition]
GROUP BY <col | expr>
[HAVING <cond>]

• ORDER BY clause can be used to order the final result


Order of Execution

• It chooses rows based on the where clause

• It groups those rows together based on the group by.

• It calculates the results of the group functions for each group.

• It chooses and eliminates groups based on the having clause

• It orders the groups based on the results of the group


functions in the order by. The order by must use either a
group function or a column in the group by clause.
USING GROUP BY
SELECT COUNT(*),DEPTNO SELECT AVG(SAL),JOB

FROM EMP FROM EMP

GROUP BY DEPTNO GROUP BY JOB

SELECT MAX(SAL),JOB SELECT MIN(SAL),JOB

FROM EMP FROM EMP

GROUP BY JOB GROUP BY JOB

SELECT SUMSAL),JOB

FROM EMP

GROUP BY JOB
USING GROUP BY
SELECT COUNT(*),DEPTNO SELECT AVG(SAL),JOB

FROM EMP FROM EMP

GROUP BY JOB GROUP BY DEPTNO

NOT A GROUP
BY EXPRESSION

OTHER THAN AGGREGATE FUNCTIONS, ( COLUMNS,


EXPRESSIONS )THAT IS THERE IN SELECT LIST MUST AND
SHOULD BE THERE IN GROUP BY CLAUSE
USING GROUP BY
SELECT COUNT(*),DEPTNO SELECT AVG(SAL),JOB

FROM EMP FROM EMP

NOT A SINGLE –
GROUP
GROUPFUNCTION

USE A VALID GROUP BY CLAUSE


USING GROUP BY
SELECT COUNT(*),DEPTNO SELECT AVG(SAL),JOB

FROM EMP FROM EMP

WHERE COUNT(*)>4 WHERE AVG(SAL)>=3000

GROUP BY DEPTNO GROUP BY JOB

GROUP FUNCTION
NOT ALLOWED HERE

USE HAVING CLAUSE FOR AGGREGATE


FUNCTIONS
NESTING GROUP FUNCTIONS
SELECT COUNT(*) COUNT(*)
--------------------
FROM EMP 3
6
GROUP BY DEPTNO 5

MAX(COUNT(*)
SELECT MAX(COUNT(*))
--------------------
6
FROM EMP

GROUP BY DEPTNO
PRACTICE SESSIONS
1. List the department numbers and number of employees in each
department:
2. List the department number and the total salary payable in each
department:
3. List the jobs and the number of employees in each job. The result
should be in descending order of the number of employees:
4. List the total salary, maximum and minimum salary and the average
salary of employees job wise:
5. List the average salary for each job excluding managers
6. List the average monthly salary for each job type within department.
7. List average salary for all departments employing more than five people.
8. List jobs of all the employees where maximum salary is greater than or
equal to 3000.
9. List the total salary, maximum and minimum salary and the average
salary of the employees job wise, for department number 20 and
display only those rows having average salary greater than 1000:
10. List the number of people along with enames having ‘S’ in their name.
11. Display number of people along with the job which contains only 1 person
in that job
12. Display job along with minimum salary which has minimum salary greater
than or equal to 3000
The SET Operators

• SET Operators are used to combine information of similar type


from one or more than one table

• Datatype of corresponding columns must be the same

• The types of SET operators in ORACLE are :

• UNION : Rows of first query plus rows of second


query, less duplicate rows

• INTERSECT : Common rows from all the queries

• MINUS : Rows unique to the first query


The SET Operators
A B A B

UNION/UNION ALL

A B

INTERSECT

A B

MINUS
The SET Operators
RULES:
1. Number of columns in the select statements should be
same.

SELECT ENAME,SAL
WRONG
FROM EMP
WHERE DEPTNO=10
UNION

SELECT ENAME,SAL,JOB
FROM EMP
WHERE DEPTNO=20
The SET Operators
RULES:
2. Datatypes of the corresponding columns should be
same.

WRONG
SELECT ENAME, SAL
FROM EMP
WHERE DEPTNO=10
UNION

SELECT ENAME, JOB


FROM EMP
WHERE DEPTNO=20
The SET Operators
UNION MANAGER
SELECT JOB FROM EMP WHERE DEPTNO=10 PRESIDENT
CLERK
UNION
SELECT JOB FROM EMP WHERE DEPTNO=20

ANALYST
ANALYST
CLERK
ANALYST CLERK
CLERK MANAGER
MANAGER
PRESIDENT
The SET Operators
UNION ALL MANAGER
SELECT JOB FROM EMP WHERE DEPTNO=10 PRESIDENT
CLERK
UNION ALL
SELECT JOB FROM EMP WHERE DEPTNO=20

ANALYST
ANALYST
CLERK
CLERK CLERK
MANAGER MANAGER
PRESIDENT
ANALYST NO
ANALYST SORTING
CLERK
CLERK
MANAGER
The SET Operators
INTERSECT MANAGER
PRESIDENT
SELECT JOB FROM EMP WHERE DEPTNO=10 CLERK
INTERSECT
SELECT JOB FROM EMP WHERE DEPTNO=20

ANALYST
ANALYST
CLERK
CLERK CLERK
MANAGER MANAGER
The SET Operators
MINUS MANAGER
PRESIDENT
SELECT JOB FROM EMP WHERE DEPTNO=10 CLERK
MINUS
SELECT JOB FROM EMP WHERE DEPTNO=20

ANALYST
ANALYST
CLERK
PRESIDENT CLERK
MANAGER
PRACTICE SESSIONS

1. Display MGR in department 20 and 30


2. Use order by clause for the above query
3. List the MGR common to department 20 and
30:
4. List the MGR unique to department 20:
5. Display employee name and department
name using set operator
EMP
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
7369 SMITH CLERK 7902 17-DEC-80 800 20
7499 ALLEN SALESMAN 7698 20-FEB-81 1600 300 30
7521 WARD SALESMAN 7698 22-FEB-81 1250 500 30
7566 JONES MANAGER 7839 02-APR-81 2975 20
7654 MARTIN SALESMAN 7698 28-SEP-81 1250 1400 30
7698 BLAKE MANAGER 7839 01-MAY-81 2850 30
7782 CLARKE MANAGER 7839 09-JUN-81 2450 10
7788 SCOTT ANALYST 7566 19-APR-87 3000 20
7839 KING PRESIDENT 17-NOV-81 5000 10
7844 TURNER SALESMAN 7698 08-SEP-81 1500 30
7876 ADAMS CLERK 7788 23-MAY-87 1100 20
7900 JAMES CLERK 7698 03-DEC-81 950 30
7902 FORD ANALYST 7566 03-DEC-81 3000 20
7934 MILLER CLERK 7682 23-JAN-82 1300 10

GRADE LOSAL HISAL


DEPTNO DNAME LOC
1 700 1200
DEPT 10 ACCOUNTIG NEWYORK SALGRADE
2 1201 1400
20 RESEARCH DALLAS 3 1401 2000
30 SALES CHICKAGO 4 2001 3000
40 OPERATIONS BOSTON 5 3001 9999
JOINS
•Joins are used to combine columns
from different tables

• From clause will have table formats (O)


eg: EMP,DEPT or EMP E,DEPT D

• Type of Join Specified (S)

• Join condition uses Where(O), ON(S)

• Column Names should have format


eg: emp.ename or e.ename
JOIN SYNTAX
ORACLE PROPRIETARY
SYNTAX SQL 99 SYNTAX
(ORACLE 8i & PRIOR) (S)
(O)
• Equi Join •Inner
• Non equijoin
• Outer join • Outer Join(Left,Right,Full)
• Self join
• Cartesian • Cross
•Natural
•Using
EQUI JOIN/INNER JOIN
* Used for tables with common columns
* Uses = operator

ORACLE SYNTAX SQL 99 SYNTAX


SELECT E.ENAME,D.DNAME SELECT E.ENAME,D.DNAME

FROM EMP E,DEPT D FROM EMP E

WHERE E.DEPTNO=D.DEPTNO INNER JOIN DEPT D

ON E.DEPTNO=D.DEPTNO
OUTER JOIN
* OUTER JOIN=EQUIJOIN+MISSING DATA
EMP ENAME JOB MGR HIREDATE SAL COMM DEPTNO DEPTNO DNAME LOC
NO
10 ACCOUNTIG NEWYORK
7369 SMITH CLERK 7902 17-DEC-80 800 20

7499 ALLEN SALESMAN 7698 20-FEB-81 1600 300 30


20 RESEARCH DALLAS
7782 CLARK MANAGER 7839 20-FEB-81 2450 10
30 SALES CHICKAGO

40 OPERATIONS BOSTON

MISSING DATA

ORACLE SYNTAX SQL 99 SYNTAX


SELECT E.ENAME,D.DNAME SELECT E.ENAME,D.DNAME

FROM EMP E,DEPT D FROM EMP E

WHERE E.DEPTNO(+)=D.DEPTNO RIGHT OUTER JOIN DEPT D

ON E.DEPTNO=D.DEPTNO
OUTER JOIN
EMP ENAME JOB MGR HIREDATE SAL COMM DEPTNO
NO

7369 SMITH CLERK 7902 17-DEC-80 800 20

7499 ALLEN SALESMAN 7698 20-FEB-81 1600 300 30

7782 CLARK MANAGER 7839 20-FEB-81 2450 10

1111 RAMU
DEPTNO DNAME LOC
10 ACCOUNTIG NEWYORK
MISSING DATA
20 RESEARCH DALLAS

30 SALES CHICKAGO

40 OPERATIONS BOSTON

ORACLE SYNTAX SQL 99 SYNTAX


SELECT E.ENAME,D.DNAME SELECT E.ENAME,D.DNAME

FROM EMP E,DEPT D FROM EMP E

WHERE E.DEPTNO=D.DEPTNO(+) LEFT OUTER JOIN DEPT D

ON E.DEPTNO=D.DEPTNO
OUTER JOIN
EMP ENAME JOB MGR HIREDATE SAL COMM DEPTNO DEPTNO DNAME LOC
NO
10 ACCOUNTIG NEWYORK
7369 SMITH CLERK 7902 17-DEC-80 800 20

7499 ALLEN SALESMAN 7698 20-FEB-81 1600 300 30 20 RESEARCH DALLAS

7782 CLARK MANAGER 7839 20-FEB-81 2450 10 30 SALES CHICKAGO


1111 RAMU
40 OPERATIONS BOSTON

MISSING DATA

ORACLE SYNTAX SQL 99 SYNTAX


SELECT E.ENAME,D.DNAME SELECT E.ENAME,D.DNAME

FROM EMP E,DEPT D FROM EMP E

WHERE E.DEPTNO=D.DEPTNO(+) FULL OUTER JOIN DEPT D


UNION
SELECT E.ENAME,D.DNAME ON E.DEPTNO=D.DEPTNO

FROM EMP E,DEPT D

WHERE E.DEPTNO(+)=D.DEPTNO
Rules to place (+) operator

• The outer join symbol ( + ) can not be on both the


sides.

• We can not "outer join" the same table to more


than one other table in a single SELECT statement.

• A condition involving an outer join may not use the


IN operator or be linked to another condition by the
OR operator.
NON EQUI JOIN
* Used for tables without common columns
* Uses other than = operator

ORACLE SYNTAX SQL 99 SYNTAX


SELECT E.ENAME,E.SAL,S.GRADE SELECT E.ENAME,E.SAL,S.GRADE

FROM EMP E,SALGRADE S FROM EMP E

WHERE E.SAL JOIN SALGRADE S

BETWEEN S.LOSAL ON E.SAL

AND S.HISAL BETWEEN S.LOSAL

AND S.HISAL
SELF JOIN
* Table is joined to the table itself

EMP E EMP M

EMPNO ENAME MGR = EMPNO ENAME MGR


7369 SMITH 7902 7369 SMITH 7902
7902 FORD 7566 7902 FORD 7566
7566 JONES 7839 7566 JONES 7839
7839 KING - 7839 KING -
SELF JOIN
* Table is joined to the table itself

ORACLE SYNTAX SQL 99 SYNTAX


SELECT E.ENAME “EMPLOYEE”, SELECT E.ENAME “EMPLOYEE”,
M.ENAME “MANAGER” M.ENAME “MANAGER”

FROM EMP E,EMP M FROM EMP E

WHERE E.MGR=M.EMPNO JOIN EMP M

ON E.MGR=M.EMPNO
Cross Joins
(Cartesian product )

A Cartesian product is formed when:


•A join condition is omitted
•A join condition is invalid
•All rows in the first table are joined
to all rows in the second table
•To avoid a Cartesian product, always
include a valid join condition in a
WHERE clause.
Generating a Cartesian Product
EMPLOYEES (20 rows) DEPARTMENTS (8 rows)

Cartesian
product:
20x8=160 rows

SQL > SELECT * FROM EMP CROSS JOIN DEPT;

SQL > SELECT EMPNO,ENAME,JOB,EMP.DEPTNO,DNAME,LOC


FROM EMP CROSS JOIN DEPT
NATURAL JOIN
* Naturally tables joined on common columns
•Common columns in both the tables should have same datatype
• Cant specify column on which join should be done

SQL 99 SYNTAX
SELECT ENAME ,DNAME

FROM EMP

NATURAL JOIN DEPT


USING CLAUSE
* When multiple columns are there we can specify which column
should be used for joining
•Suitable for Common columns in both the tables with different
datatype

SQL 99 SYNTAX
SELECT ENAME ,DNAME

FROM EMP

JOIN DEPT

USING (DEPTNO)
PRACTICE SESSIONS-1
1. List the employee numbers, names, department numbers
and the department name
2. List all employees who joined the company before their
manager.
3. Select employees name with reporting manager.
4. List all employees who are earning more than
manager’s.
5. Write a query to display employee name,managername
and manager’s department name.
6. Display all the employees who are in sales department
and not reporting to Blake.
7. Find the department name where maximum numbers of
employees are working.
8. Find employees who are working in ACCOUNTING,
RESEARCH department as CLERK with a salary more
than 800.
PRACTICE SESSIONS-2
1. List deptno, dname along with total salary in each department.
2. List details from emp, dept and salgrade table excluding clerks and
employees with grade 1. Order on their names.
3. List employee with grade 3 or 4
4. List employees located in dallas.
5. List ename, job, sal, grade, dname with annual remuneration greater
than 36000 or any clerks.
6. List employee and department details for department 30 and 40.
7. List all employees who earn less than their managers. List their
managers details also.
8. Find the job that was filled in first half of 1982 and the same job that
was filled during first half of 1983
9. Find all employees who draw salary more than their manager
10. Display all clerks and their reporting managers
What Is a Subquery?

A subquery is a SELECT statement


embedded in a clause of another SQL
statement.
Main SELECT ...
query FROM ...
WHERE ...
(SELECT ... Subquery
FROM ...
WHERE ...)
Subquery

SELECT select_list
FROM table
WHERE expr operator (SELECT select_list
FROM table);

• The subquery (inner query) executes


once before the main query.
• The result of the subquery is used by
the main query (outer query).
• Sub query should be enclosed in
brackets
Subquery

SELECT ename
OUTER
FROM emp
QUERY WHERE sal >
>

2975
(SELECT sal
SUB
FROM emp
QUERY WHERE ename=‘JONES’)

ENAME
----------
SCOTT
KING
FORD
Subquery

TYPES

•SINGLE ROW
•MULTIPLE ROW
•MULTIPLE COLUMN
•NESTED
•CORRELATED
Subquery
Multiple row subquery using IN

SELECT ename,sal
OUTER
FROM emp
QUERY WHERE sal IN
>

3000,1250
(SELECT sal
SUB
FROM emp
QUERY WHERE ename in(‘FORD’,’MARTIN’)

ENAME SAL
---------- -------
SCOTT 3000
WARD 1250
Subquery
Multiple row subquery using ANY

SELECT ename,sal
OUTER
FROM emp
QUERY WHERE sal > ANY
>

(SELECT sal 1500,1300,1100


FROM emp
SUB WHERE ename
QUERY
in(‘TURNER’,’MILLER,’ADAMS’,)

ENAME SAL
---------- ----------
KING 5000
FORD 3000
SCOTT 3000
JONES 2975
BLAKE 2850
CLARK 2450
ALLEN 1600
TURNER 1500
MILLER 1300
MARTIN 1250
WARD 1250
Subquery
Multiple row subquery using ALL

SELECT ename,sal
OUTER
FROM emp
QUERY WHERE sal > ALL
>

(SELECT sal 1500,1300,1100


FROM emp
SUB WHERE ename
QUERY
in(‘TURNER’,’MILLER,’ADAMS’,)

ENAME SAL
---------- ----------
KING 5000
FORD 3000
SCOTT 3000
JONES 2975
BLAKE 2850
CLARK 2450
Subquery
Multiple COLUMN subquery

SELECT ename,sal,deptno
OUTER
FROM emp
QUERY WHERE (deptno,sal) IN

>

(SELECT deptno,max(sal) 20,3000


FROM emp
SUB WHERE deptno=20
QUERY
GROUP BY deptno)

ENAME DEPTNO SAL


---------- -------------- ----------
SCOTT 20 3000
FORD 20 3000
Subquery
Correlated subquery

SELECT ename,sal,deptno
FROM emp
OUTER WHERE sal >
QUERY
Ename Sal deptno
>
Smith 800 20

(SELECT avg(sal)
from emp
?)
SUB
QUERY where deptno=
Subquery
Correlated subquery

SELECT ename,sal,deptno
FROM emp E
OUTER
QUERY
WHERE sal >
Ename Sal deptno
>
Smith 800 20

(SELECT avg(sal)
from emp
SUB where deptno=E.deptno)
QUERY
Subquery
NESTED subquery

SELECT ename,job
FROM emp
OUTER
QUERY
WHERE job in

>
CLERK,SALESMAN

(SELECT job
FROM emp
GROUP BY job
SUB having
QUERY
count(*) in
ENAME JOB
(SELECT MAX(COUNT(*))
----------
SMITH
-------------------
CLERK
FROM emp
ADAMS CLERK GROUP by job))
JAMES CLERK
MILLER CLERK
ALLEN SALESMAN
WARD SALESMAN
MARTIN SALESMAN
TURNER SALESMAN
PRACTICE SESSIONS-1
1. List employee working under KING
2. List department with maximum average salary.
3. Find employees who earn highest salary in each job type.
4. Find employees who earn minimum salary for each job type excluding
clerks. Sort on their salary.
5. Find most recently hired employee in each department. Order by
hiredate.
6. List departments for which no employees exists.
7. In which year did most people join the company. Display the year and
no of employees
8. Display department with maximum average salary.
9. Write a query to list enames with job having maximum no., of
employees
10. Write a query to list enames having maximum number of characters
in their name
PRACTICE SESSIONS-2
1. Create a query to display the employee numbers and names of all
employees who earn more than the average salary. Sort the results in
descending order of salary.
2. Write a query to display the last name and hire date of any employee in
the same department as BLAKE.Exclude BLAKE.
3. Find the department name of Mr.SMITH.
4. Write a query to display all employees who have joined after Mr.JONES.
5. Show the department numbers, names, and locations of the
departments where no sales representatives work.
6. Display Name,Job,Salary ofemployees who are having salaries more
than salesman. Arrange the data from highest to lowest.
7. Find all employees who have been with the company longer than any
top-level manager.
8. List the employees of dept 20 who have same job as that of sales
department.
9. Find out names of the employees who have joined on the same date
PRACTICE SESSIONS-3
1. Find out the seniormost SALESMAN
2. Find out the Juniormost Manager
3. Find the highest paid SALESMAN
4. Fiind the lowest paid Manager
ROLLUP
The ROLLUP function allows the creation of sorted subtotals
at every level of an aggregation up to the sum total.
ROLLUP first calculates the aggregates specified in the
GROUP BY clause. Subtotals of the higher levels are then
created progressively, navigating from right to left through
the grouping attributes. Finally, the sum total is output
SELECT deptno, job, COUNT(*),
SUM(sal)
FROM emp
GROUP BY rollup(deptno, job);
CUBE
The CUBE function forms all possible combinations of
subtotals, including the sum total.
This allows very simple cross-classified table reports, such as
are necessary in drill-down functionalities of client tools. With
multi-dimensional analyses, the CUBE function generates all
the subtotals that can be formed for a cube with the specified
dimensions
SELECT deptno, job, COUNT(*),
SUM(sal)
FROM emp
GROUP BY cube(deptno, job )
GRANT & REVOKE
GRANT IS USED FOR GIVING PRIVILEGES TO USERS

REVOKE IS USED TO WITHDRAW THE PRIVILEGES FROM USERS


What Is a Sequence?

A sequence:
• Automatically generates unique
numbers
• Is a sharable object
• Is typically used to create a primary
key value
• Replaces application code
• Speeds up the efficiency of accessing
sequence values when cached in
memory
The CREATE SEQUENCE Statement
Syntax

Define a sequence to generate sequential


numbers automatically.

CREATE SEQUENCE sequence


[INCREMENT BY n]
[START WITH n]
[{MAXVALUE n | NOMAXVALUE}]
[{MINVALUE n | NOMINVALUE}]
[{CYCLE | NOCYCLE}]
[{CACHE n | NOCACHE}];
Creating a Sequence
• Create a sequence named
DEPT_DEPTID_SEQ to be used for the
primary key of the DEPARTMENTS table.
• Do not use the CYCLE option.
CREATE SEQUENCE dept_deptid_seq
INCREMENT BY 10
START WITH 120
MAXVALUE 9999
NOCACHE
NOCYCLE;
Sequence created.
Confirming Sequences

• Verify your sequence values in the


USER_SEQUENCES data dictionary
table.sequence_name, min_value, max_value,
SELECT
increment_by, last_number
FROM user_sequences;

• The LAST_NUMBER column displays


the next available sequence number
if NOCACHE is specified.
NEXTVAL and CURRVAL
Pseudocolumns
• NEXTVAL returns the next available
sequence value.
It returns a unique value every time it is
referenced,
even for different users.
• CURRVAL obtains the current sequence
value.
• NEXTVAL must be issued for that
sequence before CURRVAL contains a
value.
Using a Sequence

• Insert a new department named


“Support” in department no 250.
INSERT INTO dept(deptno,
dname, loc)
VALUES (dept_deptid_seq.NEXTVAL,
'Support', 250);
1 row created.

• View the current value for the


DEPT_DEPTID_SEQ sequence.
SELECT dept_deptid_seq.CURRVAL
FROM dual;
Using a Sequence
• Caching sequence values in memory
gives faster access to those values.
• Gaps in sequence values can occur
when:
– A rollback occurs
– The system crashes
– A sequence is used in another table
• If the sequence was created with
NOCACHE, view the next available
value, by querying the
USER_SEQUENCES table.
Removing a Sequence

• Remove a sequence from the data


dictionary by using the DROP
SEQUENCE statement.
• Once removed, the sequence can no
longer be referenced.
DROP SEQUENCE dept_deptid_seq;
Sequence dropped.
SEQUENCES

1.Create a sequence to be used with the primary key column of the DEPT table. The
sequence should start at 200 and have a maximum value of 1000. Have your
sequence increment by ten numbers. Name the sequence DEPT_ID_SEQ.

2.Write a query in a script to display the following information about your sequences:
sequence name, maximum value, increment size, and last number.

3 Write a script to insert two rows into the DEPT table. Be sure to use the sequence
that you created for the ID column. Add two departments named Education and
Administration. Confirm your additions.
VIEWS
developer
enduser

Not conversant with complex Worried about table security


query/joins

•Very Handy for both developer and enduser

• You can give partial rows/columns for


access

• Virtual table
VIEWS

CREATE OR REPLACE
VIEW V1
AS SELECT *
FROM EMP
VIEWS

GROUP
GROUP BY FUNCTIONS

NO DMLS
ON VIEW

UNION
OPERATOR DISTINCT
VIEW WITH CHECK OPTION
•Specifies the level of checking to be done when inserting or
updating data through a view.

CREATE VIEW V2
AS SELECT * FROM EMP
WHERE DEPTNO=10 WITH CHECK OPTION

UPDATE V2 SET DEPTNO=40 DEPTNO TO


BE ONLY
.
10
VIEWS
Department 30 needs access to its employee data.
1. Create a view named V$DEPT30 that contains the employee
numbers, employee names, and department numbers for all employees
in department 30.
2. Label the view columns EMPLOYEE_NO, EMPLOYEE_NAME , and
DEPARTMNT_NO .
For security purposes, do not allow an employee to
be reassigned to another department through the view.

3. SELECT THE DATA FROM VIEW

4. TRY TO ASSIGN DIFFERENT DEPARTMENT NUMBER TO MR.TURNER


VIEWS

1.create a view which consists of employees who have


joined in the second half of their joining year.

2. Use the view to select only the customers having s in


their name

3. Create a view to have details of employees where empno


is less than 7654(with check option)
Try inserting a row with empno
7700 and EMPLOYEE name "new"
Indexes

• An index used to speed retrieval of rows


in a table.

• The index contains only the indexed


value– usually the key(S)– and a pointer
to the row in the table.

122
INDEXES
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO

x 7369 SMITH CLERK 7902 17-DEC-80 800 20


x 7499 ALLEN SALESMAN 7698 20-FEB-81 1600 300 30
x 7521 WARD SALESMAN 7698 20-FEB-81 1250 500 30
7566 JONES MANAGER 7839 20-FEB-81 2975 20
x 7654 MARTIN SALESMAN 7698 20-FEB-81 1250 1400 30
x 7698 BLAKE MANAGER 7839 20-FEB-81 2850 30
x 7782 CLARKE MANAGER 7839 20-FEB-81 2450 10
x 7788 SCOTT ANALYST 7566 20-FEB-81 3000 20
x 7839 KING PRESIDENT 20-FEB-81 5000 10
x 7844 TURNER SALESMAN 7698 20-FEB-81 1500 30
7876 ADAMS CLERK 7788 20-FEB-81 1100 20
x
x 7900 JAMES CLERK 7698 20-FEB-81 950 30
7902 FORD ANALYST 7566 20-FEB-81 3000 20
x
7934 MILLER CLERK 7682 20-FEB-81 1300 10
x

Select ename No Index on Empno


from emp column.
where empno=7566; FTS will be done

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy