Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
7 views

SQL(Notes)

The document provides comprehensive notes on SQL, covering fundamental concepts such as data, databases, DBMS, RDBMS, and SQL itself. It explains basic operations, data types, constraints, and differences between various database systems, along with SQL commands and functions. Additionally, it discusses the relational model, query language, and various operators used in SQL.

Uploaded by

precioustime769
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)
7 views

SQL(Notes)

The document provides comprehensive notes on SQL, covering fundamental concepts such as data, databases, DBMS, RDBMS, and SQL itself. It explains basic operations, data types, constraints, and differences between various database systems, along with SQL commands and functions. Additionally, it discusses the relational model, query language, and various operators used in SQL.

Uploaded by

precioustime769
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/ 49

SQL Notes

1. What is Data ?

Ans

Data is raw fact which describes the attribute of an Entity.

where:

attribute —> (Properties)


Entity —> (Object)

2. What is Database ?

Ans

It is a place where data can be stored in systematic and organized manner.

3. What are the basic operation performed on Database ?

Ans

We can perform CRUD operation, it means

1. Create / Insert

2. Read / Retrieve

3. Update / Modify

4. Delete / Drop

4. What is DBMS ? (Data Base Management System)

Ans

DBMS is a software we use to maintain and manage Database.

We use Query language to communicate with DBMS.

Two Important factor are :-

1. Security

2. Authorization

Types of DBMS software

1. NDBMS (Network Data Base Management System)

SQL Notes 1
2. HDBMS (Hierarchical Data Base Management System)

3. OODBMS (Object-Oriented Data Base Management System)

4. RDBMS (Relational Data Base Management System)

5. What is RDBMS ? (Relational Data Base Management System)

Ans

It is a type of DBMS software where data will be stored in form of table.

We use Structural Query language to communicate RDBMS.

Two Important factor are :-

1. Security

2. Authorization

6. What is relational Model ?

Ans

It is a concept designed by data scientist “E.F Codd”

In Relational model, we store the data in the form tables.

A DBMS which follows Relational Model becomes RDBMS.

DBMS ——follows—> Relational Model ——>RDBMS

7. Terminologies ?

Ans

Table

Table is a logical organization of data which consist of rows and columns.

Column

Column is also referred as attribute of fields.

Rows

Rows also referred and records or tupples.

Cell

Cell is the smallest unit in the table in which we store data. the intersection of
rows and column generate cells.

SQL Notes 2
Entity

Anything which has its existence.

8. What is SQL ? why we need SQL ?

Ans

“Structural Query Language”

“Standard Query Language”

“sequel language”

SQL is used for accessing, manipulating, and communicating with the database.
Almost every function such as retrieving the data from the database, creating a
new database, insertion, deletion and updating can be performed by using SQL.

What is Query ?

Query is a condition that is written by following syntax to retrieve data from


Database.

or

Query is a computer programming language that requests and retrieve the


data from database by sending queries.

What is Structure in SQL ? or Why SQL is called as Structural Query language ?

SQL needs a structure for all its objects- like table creation, procedure
creation etc. There is the common structure to create each database objects.
that is why we call it as a Structural.

or

SQL works on user entered structured and formal programming command


based queries to find and extract data from host databases

2. Difference between DBMS & RDBMS ?

Ans

In DBMS, data is stored as file, whereas in RDBMS, data is stored in the


form of tables.

RDBMS DBMS

1) Data is stored in Table format. 1) Data is stored in File format.

SQL Notes 3
RDBMS DBMS

2) Data can be store in Large amount. 2) Data is stored in Small amount.

3) RDBMS supports Multiple User. 3) DBMS supports Single User.

4) While handling data, It provides multiple 4) While handling data, It provides low
layers of Security. Security.
5) We can access Multiple data together. 5) We can access Individual data together.

6) Table data will be linked together. 6) There is no connection between data.

7) Normalization is not available. 7) Normalization is available.

8) Data redundancy is reduced with help


8) Data redundancy is comman.
the help of key and indexes

9) It is requires high software and


9) It is requires low software and hardware.
hardware.

10) Ex: Oracle, SQL Server. 10) Ex: XML, Microsoft Access.

3. Difference between RDBMS & Excel-Sheet ?

Ans

RDBMS Excel Sheet

1) RDBMS follows EF Codd rule (or) 1) Excel Sheet does not follows EF Codd rule
Relational Model. (or) Relational Model.

2) We can store huge amount of data. 2) We can store limited amount of data.

3) It has the features of data security. 3) It does not has the features of data security.

4) Data retrieval is not Easy. we cannot use


4) Data retrieval is Easy. by using Queries.
Queires here

5) We can store META data. 5) We cannot store META data.

Note : META data means details about the data.

4. Explain rules for E.F Codd ?

Ans

The data stored in the cell must be a single value data.

In RDBMS we store everything in the form of tables including META data (the
details about the data is META data)

According to the E.F Codd we can store data in multiple tables, if need we can
establish connection between two tables using key-attributes.

SQL Notes 4
We can validate the data entered into the table in two step. 1). Assigning data-
type 2).Assigning constraints.

5. Name some RDBMS Database ?

Ans

5. Explain Data-types ?

Ans

Data types are used to determine the what kind of data we are going to store in
memory location. 5types of data-types in SQL.

char

char data type can accept character such as ‘A-B’, ’a-b’, ‘0-9’ or any special
character.

It is mandatory to provide size for it.

Maximum size of char is 2000.

It is a type of “Fixed length memory allocation”

There is a wastage of memory in char.

varchar/varchar2

varchar data type can accept character such as ‘A-B’, ’a-b’, ‘0-9’ or any
special character.

It is mandatory to provide size for it.

Maximum size of varchar is 2000.

It is a type of “Variable length memory allocation”

There is no wastage of memory in varchar.

varchar2 is updated version of varchar i.e size is updated to 4000.

number

number data-type is used to store the numerical values.

It can accept arguments 1).Precision 2).Scale

SQL Notes 5
Scale is use to determine the number of digits we are going to store in
decimal place within the precision

maximum precision we can store is 38.

maximum Scale we can store is 127.

date

Two oracle specified date formats are. 1).’DD-MON-YY 2). ‘DD-MON-YYYY’

large object

CLOB (character large object)


This is use to store the character up to 4GB of size.

BLOB (Binary large object)


This is use to store the binary number of images, videos, file etc. up to 4GB

6. Difference between char and varchar ?

Ans

7. Explain types Constraints ?

Ans

Constraints are the condition that are assigned to a particular column to validate
the data.

We have 5 types of constraints

Unique

Unique is a constraints which is assigned to a particular column which


cannot accept repeated or duplicate value.

SQL Notes 6
Not null

Not null is a constraints which is assigned to a particular column which


cannot accept Null.

Check

Check is a constraint which is assigned to a particular column for extra


validation.

Primary key

Primary key is a constraint which is used to assigned to a particular


column to identify a record uniquely from the table.

Foreign key

Foreign key is constraint which is used to establish the connection


between two tables.

8. What is the difference between Primary key and Foreign key ?

Ans

Primary Key Foreign Key

1) We can have only One Primary key in a 1) We can have n number of Foreign key in a
table. table.

2) It cannot accept repeated (or) duplicate 2) It can accept repeated (or) duplicate values
values and also Null. and also Null.

3) It is not a combination of Unique and Not-


3) It is combination of Unique and Not-Null.
Null.

4) Primary key is not mandatory but 4) Foreign key also called as “Referential
recommended to have one in Table. Integrity Constraints”

5) It is present in child table but actually


belons to parent table.

6) Only Primary key can travel to another


table when it travels it becomes Foreign Key.

9. Why we use check constraints ?

Ans

Check is a constraint which is assigned to particular column for extra validation.

SQL Notes 7
Check constraints is assigned with a condition, if the condition is true the value
gets accepted, else rejected.

10. Explain types of DQL ?

Ans

DATA QUREY LANGUAGE

SELECT

This statement is used to retrieve the data from database and display it.

PROJECTION

This statement is used to retrieve the data from database by selecting only
column.

SELECTION

This statement is used to retrieve the data from database by selecting both
column as well as records.

JOINS

This statement is used to retrieve the data from multiple tables


simultaneously.

11. Why we use Astricks ?

Ans

It used to determine “To select all the column”.

12. Why we use Alias concept ?

Ans

Alias is an alternative name given to a column or an expression in the result


table.

Alias name can be used with or without using ‘AS’ keyword.

Alias names should be in Single word or String enclosed with double quotes.

Alias is not mandatory but we recommended to provide.

13. Explain all clauses with order of execution ?

Ans

SQL Notes 8
13. Difference between Unique and Distinct clause ?

Ans

DISTINCT UNIQUE

1) Distinct is a clause. 1) Unique is a constraint.

3) Unique constraint will helps to


2) Distinct clause will helps to remove
prevent from insertion of duplicate
duplicate or repeated values.
(or) repeated values.
3) Distinct clause is used to retrieve data 3) Unique constraint is used to assign
from Column. to a column.

old

14. Difference between Distinct clause and where clause?

Ans
Filter condition =

15. Explain types of Operators ?

Ans

Arithmetic operator

+, -, *, /, %

Comparison Operator

=,≠

Relational Operator

SQL Notes 9
>, <, ≥, ≤

Logical Operator

AND, OR, NOT

1. AND= Binary multiplication, return true if both condition satisfied true.

2. OR= Binary addition, return true if any one condition satisfied true.

3. NOT= It is used Negation.

Concatenation Operator

||

Special Operator

(IN, NOT IN), (BETWEEN,NOT BETWEEN), (LIKE,NOT LIKE), (IS,IS NOT)

IN=

IN

1. It is multi valued operator

2. return true if any one condition satisfied true, replacement of OR


operator & equal Operator.

NOT IN

same as IN operator but it rejects the value instead of selecting it.

BETWEEN

used whenever we have ranges

NOT BETWEEN
same as BETWEEN operator but it rejects the value instead of selecting it

LIKE
used to match the pattern

NOT LIKE

same as LIKE operator but it rejects the value instead of selecting it

IS

used only to compare with NULL

IS NOT

SQL Notes 10
same as IS operator but it rejects the value instead of selecting it.

Sub-Query Operator
ALL, ANY

ALL

1. is a special operator which can accept multi values at RHS.

2. It will return true only if all the condition at RHS is satisfied

ANY

1. is a special operator which can accept multi values at RHS.

2. It will return true only if any one of the condition at RHS is satisfied

16. Why we use Like Operator ?

Ans

LIKE operator is used whenever we need to “match the pattern”.

17. Explain about Sub-Query and Difference between Single row sub-query and multi row
Sub-query ?

Ans

Sub-Query = Query written inside another Query.

In this query we have 2 query 1).Outer query 2). Inner query

Inner query will execute first and generate the output. that output is input for
outer query and output of outer query is the result.

when we use sub-query.

1). whenever we have unknow

2).when ever the data to be select and condition to be executed are present in
different tables we use sub-query.

Types of Sub-query.

1).Single row Sub-query.

which returns exactly one output.

we can use operator such as IN,NOT ĪN,ALL,ANY.

2).Multi-row sub-query.

SQL Notes 11
which returns more then one output.

we must use IN,NOT ĪN,ALL,ANY.

18. Explain about Function ?

Ans

Function is the list of instruction that are used to perform some specific task.
Function has 2 type,

User-defined function.
.

In-built function. (has 2 types)

Single-row Function

Single row function executes row-by-row.

It takes one input and generate one output then goes to the next input.

If we pass ‘n’ number of input to single row function, it returns ‘n’ number
of output.

There are 13 Single Row Function , we have :-

Dual

Dual is a dummy table use to print the result of any mathematic


operation done.

UPPER

UPPER() function is used to convert the given String into upper


case.

Syntax

SELECT UPPPER('STRING')
FROM DUAL;

Example

SELECT UPPPER('manu')
FROM DUAL;
----------OUTPUT--------
MANU

SQL Notes 12
LOWER

LOWER() function is used to convert the given String into lower


case.

Syntax

SELECT LOWER('STRING')
FROM DUAL;

Example

SELECT LOWER('MANU')
FROM DUAL;
---------OUTPUT------------
manu

INITCAP

INITCAP() function is used to convert the initial character of given


String into upper case.

Syntax

SELECT INITCAP ("STRING")


FROM DUAL;

Example

SELECT INITCAP ("manu km")


FROM DUAL;
-----------OUTPUT---------
Manu Km

LENGTH

LENGTH() function is used to count the number of character that are


present in the String.

Syntax

SQL Notes 13
SELECT LENGTH('String')
FROM DUAL;

Example

SELECT LENGTH('MANU')
FROM DUAL;
--------OUTPUT----------
4

1. WQTD Ename who are having only 5charactar in their name


using SRF ?

Ans

SELECT ENAME
FROM EMP
WHERE LENGTH(ENAME)=5;

REVERSE

REVERSE() function is used to reverse the given String.

Syntax

SELECT REVERSE('String')
FROM DUAL;

Example

SELECT REVERSE('MANU')
FROM DUAL;
-----------OUTPUT--------
UNAM

SUBSTR

SUBSTR() function used to extract the part of the String from the
given original String.

Syntax

SQL Notes 14
SELECT SUBSTR("ORIGINAL_STRING",POSITION[LENGTH])
FROM DUAL;

Example

SELECT SUBSTR("BANGALORE",1,1)
FROM DUAL; //B

SELECT SUBSTR("BANGALORE",0,0)
FROM DUAL; //

SELECT SUBSTR("BANGALORE",1,2)
FROM DUAL; //BA

SELECT SUBSTR("BANGALORE",0,2)
FROM DUAL; //BA

SELECT SUBSTR("BANGALORE",1,3)
FROM DUAL; //BAN

SELECT SUBSTR("BANGALORE",0,3)
FROM DUAL; //BAN

SELECT SUBSTR("BANGALORE",1,5)
FROM DUAL; //BANGA

SELECT SUBSTR("BANGALORE", ,1)


FROM DUAL; //BANGALORE

SELECT SUBSTR("BANGALORE", ,3)


FROM DUAL; //NGALORE

SELECT SUBSTR("BANGALORE",-2,2)
FROM DUAL; //RE

SELECT SUBSTR("BANGALORE",-3,2)
FROM DUAL; //L

1. WQTD employees name whose names starts with VOWEL


(A,E,I,O,U) ?

Ans

SELECT ENAME
FROM EMP
WHERE SUBSTR(ENAME,0,1) in ('A','E','I','O','U');

SQL Notes 15
2. WQTD Ename and job of emp’s, if the job starts with String
MAN or ends with String MAN ?

Ans

SELECT ENAME,JOB
FROM EMP
WHERE SUBSTR(JOB,1,3) IN 'MAN' OR
SUBSTR(JOB,-3,3) IN 'MAN';

3. WQTD Ename in lower case and job in reverse format, if the


emp’s name having 6 character ?

Ans

SELECT LOWER(ENAME),REVERSE(JOB)
FROM EMP
WHERE LENGTH(ENAME)=6;

4. WQTD Details of emp’s, if their name starts with ‘A’ or ‘S’


using SRF (Single Row Function) ?

Ans

SELECT *
FROM EMP
WHERE SUBSTR(ENAME,1,1) IN 'A' OR
SUBSTR(ENAME,1,1) IN 'S';

5. WQTD the first three character of all the employees ?

Ans

SELECT ENAME
FROM EMP
WHERE SUBSTR(ENAME,1,3);

6. WQTD Details of emp’s, if their name starts with ‘A’ using


SRF (Single Row Function) ?

Ans

SQL Notes 16
SELECT *
FROM EMP
WHERE SUBSTR(ENAME,1,1) IN 'A';

7. WQTD first character of all the employees from employee


table ?

Ans

SELECT SUBSTR(ENAME,1,1)
FROM EMP;

MOD

MOD() function is used to obtain modules of the given number.


(Reminder)

Syntax

SELECT column-name
FROM table-name
WHERE MOD(column-name,2)=1; --> (for Odd)

(or)

SELECT column-name
FROM table-name
WHERE MOD(column-name,2)=0; --> (for Even)

Example

1. WQTD details of employees whose Empno is an odd


number ?

Ans

SELECT *
FROM EMP
WHERE MOD(EMPNO,2)=1;

2. WQTD details of employees whose Empno is an even


number ?

SQL Notes 17
Ans

SELECT *
FROM EMP
WHERE MOD(EMPNO,2)=0;

TO_CHAR

TO_CHAR() function is used to convert the given String date to


string format.

Syntax

TO_CHAR (date,'format-model')

Example (current date)

---------For full Date---------------------------


SELECT TO_CHAR(SYSDATE,'DY-MON-YEAR')
FROM DUAL; //FRI-NOV-TWENTY TWENTY-TWO

---------For only Day---------------------------


SELECT TO_CHAR(SYSDATE,'DY')
FROM DUAL; //FRI

---------For only Month-------------------------


SELECT TO_CHAR(SYSDATE,'MON')
FROM DUAL; //NOV

---------For only Year--------------------------


SELECT TO_CHAR(SYSDATE,'YEAR')
FROM DUAL; //TWENTY TWENTY-TWO

Example

1. WQTD Employees name, who were hired in the month FEB


?

Ans

SELECT ENAME
FROM EMP
WHERE HIREDATE LIKE '%FEB%';

SQL Notes 18
2. WQTD Employees name, who were hired in the month FEB
Using SRF?

Ans

SELECT ENAME
FROM EMP
WHERE TO_CHAR (HIREDATE,'MON') IN 'FEB';

3. WQTD Employees name, who were hired in the month


FEB,NOV,DEC Using SRF?

Ans

SELECT ENAME
FROM EMP
WHERE TO_CHAR (HIREDATE,'MON') IN ('OCT','NOV','DEC');

4. WQTD details of employees, who were hired on wednesday


or monday Using SRF?

Ans

SELECT *
FROM EMP
WHERE TO_CHAR(HIREDATE,'DY') IN ('MON','WED');

5. WQTD Employees name, who were hired in the year


81,83,84 Using SRF?

Ans

SELECT *
FRROM EMP
WHERE TO_CHAR(HIREDATE,'YY') IN (81,83,84);

6. WQTD Details of employees, who were hired on 17,19 or 22


Using SRF?

Ans

SQL Notes 19
SELECT *
FROM EMP
WHERE TO_CHAR(HIREDATE,'DD') IN (17,18,19,22);

SYSDATE / CURRENT_DATE

SYSDATE is used to obtain the Present date from the Database.

Syntax

SYSDATE OR CURRENT_DATE

Example

SELECT SYSDATE
FROM DUAL;

(OR)

SELECT CURRENT_DATE
FROM DUAL;

SYSTIMESTAMP

SYSTIMESTAMP function is used to obtain the date and time along


with time zone.

Syntax

SYSTIMESTAMP

Example

SELECT SYSTIMESTAMP
FROM DUAL;

TO DATE

TO_DATE() is used to convert the date String to date format.

Syntax

SQL Notes 20
TO_CHAR('DATE_STRING')

Example

SELECT TO_CHAR(TO_DATE('29-SEP-1999'),'DAY')
FROM DUAL;
-------------OUTPUT---------
WEDNESDAY

INSTR

INSTR() function is used to obtain index value of the substring which


is present in the Original String.

Syntax

INSTR('Original-string','Sub-str',position,[Nth Occurance])

Nth occurance - No.of time, it is present.

Example

// B A N A N A
// 1 2 3 4 5 6

SELECT INSTR('BANANA','A',1,1)
FROM DUAL; //2

SELECT INSTR('BANANA','A',1,2)
FROM DUAL; //4

SELECT INSTR('BANANA','A',1,3)
FROM DUAL; //6

SELECT INSTR('BANANA','A',2,1)
FROM DUAL; //2

SELECT INSTR('BANANA','A',2,2)
FROM DUAL; //4

SELECT INSTR('BANANA','AN',1,1)
FROM DUAL; //2

SELECT INSTR('BANANA','AN',1,2)
FROM DUAL; //4

SQL Notes 21
1. WQTD details of employees, if their name having character ‘A’
Using SRF ?

Ans

SELECT *
FROM EMP
WHERE INSTR(ENAME,'A',1,1)>0;

2. WQTD Ename of employees in lower case, if employees are


having character ‘A’ present at-least twice in their name using
SRF ?

Ans

SELECT LOWER(ENAME)
FROM EMP
WHERE INSTR(ENAME,'A',1,2)>1;

Multi-Row Function / Group function / Aggregate function

Multi row function is also know as group function or aggregate function.

It executes group-by-group.

It takes all input at once and combines it and generate one output.

If we pass ‘n’ number of input to multi row function, it returns single


output.

There are 5 Multi Row Function , we have :-

1. MAX

2. MIN

3. SUM

4. AVG

5. COUNT

20. Can we use Multi-row function in where clause, if no why ?

Ans

SQL Notes 22
We cannot use use multi-row function in where clause. because where clause
executes row-by-row where as multi-row function executes group-by-group.

20. Explain about Having clause, Group by clause, Order by ?

Ans

22. Explain about Sub-String ?

Ans

SUBSTRING function used to retrieve characters from a string. we can


retrieve any number of substrings from a single string.

24. Explain about types of Join ?

Ans

Join statement is used to retrieve the data from multiple table


simultaneously.

Cartesian Join or Cross Join

In cartesian join record from table 1 will be merged with all the record
from of table 2

Inner join

we use inner join to get only the matched records.

Syntax

SELECT column-name1,column-name2
FROM table-name1,table-name2
WHERE <filter-codition>;

Example

SQL Notes 23
SELECT ENAME,DNAME
FROM EMP,DEPT
WHERE EMP.DEPTNO = DEPT.DEPTNO;

we use join condition to obtain the matched records.

join condition

It is a condition on which we merge two tables to get only the


matched record.

Syntax

table-name1.column-name = table-name2.column-name;

Example

EMP.DEPTNO = DEPT.DEPTNO;

WQTD Ename and Dname of the Employees, who are getting


commission in department 10 or 30 ?

SELECT ENAME,DNAME
FROM EMP,DEPT
WHERE EMP.DEPTNO=DEPT.DEPTNO AND COMM IS NOT NULL AND EMP.DEPTNO IN (10,30);

WQTD Ename and Empno for all the Employees, who’s Empno are
(7839,7902) and are working in location new york ?

SELECT DNAME,EMPNO
FROM EMP,DEPT
WHERE EMP.DEPTNO=DEPT.DEPTNO AND EMPNO IN (7839,7902) AND LOC IN 'NEW YORK';

WQTD Ename and Dname , who are earning more then smith ?

SELECT ENAME,DNAME
FROM EMP,DEPT
WHERE EMP.DEPTNO=DEPT.DEPTNO AND SAL>(SELECT SAL
FROM EMP
WHERE ENAME IN 'SMITH');

SQL Notes 24
Outer join

We use outer join to get the matched records along with the unmatched
records.

Left outer join

We use left outer join to get the unmatched records of left table
along with matched records.

Syntax

SELECT column-name
FROM table-name1,table-name2
WHERE table-name1.column-name = table-name2.column-name(+);

Example

SELECT *
FROM EMP,DEPT
WHERE EMP.DEPTNO=DEPT.DEPTNO(+);

Right outer join

We use right outer join to get unmatched records of right table along
with matched records.

Syntax

SELECT column-name
FROM table-name1,table-name2
WHERE table-name1.column-name(+) = table-name2.column-name;

Example

SELECT *
FROM EMP,DEPT
WHERE EMP.DEPTNO(+)=DEPT.DEPTNO(+);

Full outer join

SQL Notes 25
We use full outer join to get unmatched records of both tables along
with matched record.

Syntax

SELECT column-name
FROM table-name1 FULL OUTER JOIN table-name2
ON table-name1.column-name = table-name2.column-name;

Example

SELECT *
FROM EMP FULL OUTER JOIN DEPT
ON EMP.DEPTNO=DEPT.DEPTNO;

Self join

We use self join to join the same two table or table itself.

Why we use Self join ?

If the data to be selected and condition to be executed is present in


the same table but in different record, we use self join.

When 2 column names are same and table also same.

Syntax

SELECT column-name
FROM table-name1,table-name2
WHERE <filter-conition>;

Example

SELECT E1.ENAME,E2.ENAME
FROM EMP E1,EMP E2
WHERE E1.MGR = E2.EMPNO;

Natural join

If table contains similar column we get the output of inner join, if table
does not contains similar column we get the output of cartesian join.

SQL Notes 26
Why and When we use Natural Join ?

Whenever there is no table structure, we use natural join.

Syntax

SELECT column-name
FROM table-name1 NATURAL JOIN table-name2;

Example

SELECT *
FROM EMP NATURAL JOIN DEPT;

Note: When we use join ?

When we want select data from two or more different table

25. When we use sub-query and inner join ?

Ans

If we want to select a multiple column or single column from same table, then we
go with sub-query. (or) When ever the data to be select and condition to be
executed are present in different table, we use sub-query.

If we want to select a multiple column from two or more different table, we use
Join.

25. Explain about types of SQL statement ?

Ans

Statements are used to perform CRUD operation in Database. There are 5


statements in SQL

DDL (Data Definition Language)

DDL statement is used for create, delete, alter, rename the Table in
database.

Create

Create statement is used to create an object in database.

Syntax

SQL Notes 27
CREATE TABLE table_name
{
COLUMN-NAME-1 DATATYPE NOT NULL/ [NULL],
COLUMN-NAME-2 DATATYPE NOT NULL/ [NULL],
COLUMN-NAME-N DATATYPE NOT NULL/ [NULL],
CONSTRAINTS constraint-ref-name UNIQUE(COLUMN-NAME),
CONSTRAINTS constraint-ref-name CHECK(CONDITION),
CONSTRAINTS constraint-ref-name PRIMARY KEY(COLUMN-NAME),
CONSTRAINTS constraint-ref-name FOREIGN KEY(COLUMN-NAME),
REFERENCES parent-table-name(COLUMN-NAME)
);

Example

CREATE TABLE CUSTOMER


(
CID NUMBER(4) NOT NULL,
CNAME VARCHAR(40) NOT NULL,
CNUM NUMBER(10) NOT NULL,
ADDRESS VARCHAR(30) NOT NULL,
CONSTRAINT CID_AK PRIMARY KEY(CID),
CONSTRAINT CNUM_C CHECK(LENGTH(CNUM)=10)
);

Rename

Rename statement is used to rename the current table name to new


table name.

Syntax

RENAME current-table-name TO new-table-name;

Example

RENAME CUSTOMER TO MANU;

Alter

Alter statement is used to modify the object in database.

add new column to table

Syntax

SQL Notes 28
ALTER TABLE table-name
ADD column-name DATATYPE CONSTAINTS;

Example

ALTER TABLE CUSTOMER


ADD CMANU VARCHAR(20) NOT NULL;

/*(This Query is used for only When we created a New Table and before
Inserting the records we can assign Not Null constraint there.
But if you already created a table and inserted some records,
if we want to add New column to existing table, you should assign
constraint as Null, once we assign NULL as constraint we can
update that null to any other value but remember we cannot
insert a record to that column again which stored as a Null,
we can update that record as any another value by using
by using UPDATE statement in DML)*/

remove column from table

Syntax

ALTER TABLE table-name


DROP COLUMN column-name;

Example

ALTER TABLE CUSTOMER


DROP COLUMN CMANU;

change column name

Syntax

ALTER TABLE table-name


RENAME COLUMN current-column-name TO new-column-name;

Example

ALTER TABLE CUSTOMER


RENAME COLUMN VOTERID TO ADHAR;

SQL Notes 29
change the datatype

Syntax

ALTER TABLE table-name


MODIFY column-name new-datatype;

Example

ALTER TABLE CUSTOMER


MODIFY CNAME NUMBER(2);
(OR)
ALTER TABLE CUSTOMER
MODIFY CNAME VARCHAR(40);

change NotNull to Null

Syntax

ALTER TABLE table-name


MODIFY column-name existing-datatype NULL/NOT NULL;

Example

ALTER TABLE CUSTOMER


MODIFY MAILID VARCHAR(20) NULL;

change constraints

Synatx

//UNIQUE
ALTER TABLE table-name
ADD CONSTRAINT constraint-ref-name UNIQUE(column-name);

//CHECK
ALTER TABLE table-name
ADD CONSTRAINT constraint-ref-name CHECK(condition);

//PRIMARY KEY
ALTER TABLE table-name
ADD CONSTRAINT constraint-ref-name PRIMARY KEY(column-name);

SQL Notes 30
//FOREIGN KEY
ALTER TABLE table-name
ADD CONSTRAINT constraint-ref-name FOREIGN KEY(column-name)
REFERENCE parent-table-name(column-name);

Example

//UNIQUE
ALTER TABLE CUSTOMER
ADD CONSTRAINT VOTERID_VO UNIQUE(VOTERID);

//CHECK
ALTER TABLE CUSTOMER
ADD CONSTRAINT VOTERID_GH CHECK(LENGTH(VOTERID)=6);

//PRIMARY KEY
(i DOM'T KNOW HOW TO CHANGE PRIMARY KEY)

//FOREIGN KEY
ALTER TABLE CUSTOMER
ADD CONSTRAINT PID_O FOREIGN KEY(PID) REFERENCES PROD(PID);
ALTER TABLE CUSTOMER
ADD CONSTRAINT PID_O FOREIGN KEY(PID) REFERENCES PROD(PID);

Truncate

Truncate statement is used to delete all records from the table


permanently.

Syntax

TRUNCATE TABLE table-name;

Example

TRUNCATE TABLE CUSTOMER;


(OR)
TRUNCATE TABLE PROD

Drop

Drop statement is used to delete the table along with table structure from
the Database.

Syntax

SQL Notes 31
DROP TABLE table-name;

Example

DROP TABLE CUSTOMER;


(OR)
DROP TABLE PROD;

To view the recycle bin tables

Syntax

SHOW RECYCLEBIN;

Example

SHOW RECYCLEBIN;

To Recover the table from recycle bin : (only in ORACLE)

Syntax

FLASHBACK TABLE table-name TO BEFORE DROP;

Example

FLASHBACK TABLE CUSTOMER TO BEFORE DROP;


(OR)
FLASHBACK TABLE PROD TO BEFORE DROP;

To drop the table from recycle bin

Syntax

PURGE TABLE table-name;

Example

SQL Notes 32
PURGE TABLE CUSTOMER;
(OR)
PURGE TABLE PROD;
(OR)
PURGE TABLE MANU;

DML (Data Manipulation Language)

DML statement is used for insertion, deletion and update the records in
Database.

Insert

Insert statement is used to insert the records in the table.

Syntax

INSERT INTO table-name (column1,column2,,) values (&column1,&column2,,);

----------------------------------
/ --> (for next record)
COMMIT; --> (for end)

Example

INSERT INTO CUSTOMER (CID,CNAME,,) values (&CID,&CNAME,,);

Note:-

If we are using Insert statement means that cell or tupple must be


empty it should stored as NULL ,we cannot use Insert statement as
replacement purpose. Instead of that we should use UPDATE
statement

For Example, If our table contains or stored as NULL record, we


cannot insert it again which is stored as NULL.

Update

Update statement is used to update the records in the table.

Syntax

SQL Notes 33
UPDATE table-name
SET column1=v1,column=v2,,,
WHERE <filter-condition>

Example

UPDATE PROD
SET PNAME='RAGNAR',PRATE=20
WHERE PID=4;

1. WQTD update the 1st employee name from prod table to ‘ramesh’ ?

Ans

UPDATE PROD
SET ENAME='RAMESH'
WHERE PID=1;

2. WQTD update salary of all employees by 1000 ?

Ans

UPDATE MANU
SET SAL=SAL+1000;

Delete

Delete statement is used to delete the particular record from the table.

Syntax

DELETE
FROM table-name
WHERE <filter-condition>

Example

DELETE
FROM PROD
WHERE PID=1;

SQL Notes 34
TCL (Transection Control Language)

TCL statement is used for managing and controlling the transactions in a


database.

commit

commit statement is used to save the transaction on database.

Syntax

COMMIT;

save point

save point statement is used to mark the position on database.

Syntax

SAVEPOINT savepoint-name;

rollback

rollback statement is used to go back or undo to the previous save point.

Syntax

ROLLBACK TO save-name;

DCL (Data Control Language)

DCL is used to access permission for the stored data.

grant

grant statement is used to give the permission to another user.

Syntax

GRANT sql-statement ON table-name TO user-name;

Example

SQL Notes 35
GRANT SELECT ON PROD TO HR;

revoke

revoke statement is used to take back the permission from another user.

Syntax

REVOKE sql-statement ON table-name FROM user-name;

Example

REVOKE SELECT ON PROD FROM HR;

DQL (Data Query Language)

DQL statement is used retrieve data from Database

SELECT

This statement is used to retrieve the data from database and display it.

PROJECTION

This statement is used to retrieve the data from database by selecting


only column.

SELECTION

This statement is used to retrieve the data from database by selecting


both column as well as records.

JOINS

This statement is used to retrieve the data from multiple tables


simultaneously.

26. Explain difference between truncate, drop and delete?

Ans

SQL Notes 36
21. Explain about types of Key-attributes ?

Ans

Key-Attribute

An attribute which is used to identify a record uniquely from the table is


called Key-Attribute.

Non Key-Attributes

All attributes except key-attribute are referred as Non key-Attribute.

Prime Key-Attributes

Among all the key-Attributes, An attribute is chosen to be the main attribute


which is used to identify a record uniquely from the table is know as Prime
Key-Attributes.

Non Prime Key-Attributes

All the Key-Attributes except Prime key-Attribute are referred as Non Prime
key-Attributes.

Composite Key-Attributes

It is a combination of two or more Non key-Attributes which is used to identify


the record uniquely from the table is know as Composite Key-Attributes.

Super Key-Attributes

It is the set of all the key-Attributes.

Foreign Key-Attribute

It behaves as an Attribute of another entity to represent the relation.

23. Explain about Types of Functional Dependency ?

Ans

SQL Notes 37
Consider the relation ‘R’ with two attributes ‘X’ and ‘Y’. in which attribute ‘X’
determines attribute ‘Y’. In other words ‘X’ is dependent on ‘Y’ there exist a
Functional Dependency.

3 Types of Functional Dependency

Total Functional Dependency

If all the attributes in a relation are determined by a single attribute which is a


key attribute, then there exist Total Functional Dependency.

In Total Functional Dependency there are No anomaly and No redundancy.

Partial Functional Dependency

One of the attributes in composite key relation determines the another


attributes separately, this is know as Partial Functional Dependency.

In Partial Functional Dependency there are anomaly and redundancy.

Transitive Functional Dependency

If an attribute is determined by non-key attribute which intern is determined


by key attribute, then there exist Transitive Functional Dependency.

In Transitive Functional Dependency there are anomaly and redundancy.

27. Explain about Normalization ?

Ans

It is a process of decomposing the large table into smaller table to remove


Anomaly and Redundancy.

Anomaly= means it is a side effect which are caused during the DML operation.

Redundancy= means these are the repeated or duplicate.

28. How do you create empty table with same structure as another table ?

Ans

CREATE TABLE NEWTABLE LIKE OLDTABLE;

29. Create the following table as ‘ORDER’ by using below details. ProdID, OrderID,
Qty_sold, Price, Order_dt.

Ans

SQL Notes 38
CREATE TABLE ORDERS
(
ProdID NUMBER(4) REFERENCES products (prodid),
OrderID NUMBER(4) PRIMARY KEY,
Qty_sold NUMBER(3) CHECK (Qty_sold > 0),
Price NUMBER(8,2),
Order_dt DATE
);

13. WAQTD all the employees who are getting some comm with their designation is neither
manager nor analyst.

Ans

SELECT *
FROM EMP
WHERE COMM IS NOT NULL AND JOB NOT IN ('MANAGER','ANALYST');

14. WAQTD all the details of employees only if an employee’s manager’s manager doesn’t
have a reporting manager and he belongs to deptno 10 or 20.

Ans

SELECT *
FROM EMP E1,EMP E2,EMP E2
WHERE E1.MGR=E2.EMPNO AND E2.MGR=E3.EMPNO AND E3.MGR IS NULL AND E3.DEPTNO IN (10,20);

(or)

SELECT *
FROM EMP E1,EMP E2,EMP E3,DEPT D1,DEPT D2,DEPT D3
WHERE E1.MGR=E2.EMPNO AND E2.MGR=E3.EMPNO AND E1.DEPTNO=D1.DEPTNO
AND E2.DEPTNO=D2.DEPTNO AND E3.DEPTNO=D3.DEPTNO AND E3.MGR IS NULL
AND D3.DEPTNO IN (10,20);

15. WAQTD ename, empno and dname of the employee who are getting comm in dept 10 or
30 and empno are (7839,7902) and are working in loc new york.

Ans

SELECT E1.ENAME,E1.EMPNO,D1.DNAME
FROM EMP E1,DEPT D1
WHERE E1.DEPTNO = D1.DEPTNO AND COMM IS NOT NULL AND
E1.DEPTNO IN (10,30) AND EMPNO IN (7839,7902) AND LOC IN 'NEW YORK';

SQL Notes 39
(OR)

SELECT EMP.ENAME,EMP.EMPNO,DEPT.DNAME
FROM EMP, DEPT
WHERE EMP.DEPTNO=DEPT.DEPTNO AND COMM IS NOT NULL AND EMP.DEPTNO IN (10,30) AND
EMP.EMPNO IN (7839,7902) AND DEPT.LOC='NEW YORK';

16. List the details of the employees and hiredate who hired on a sunday in the month of
may using single row function.

Ans

SELECT *
FROM EMP
WHERE TO_CHAR(HIREDATE,'DY')='SUN' AND TO_CHAR(HIREDATE,'MON')='MAY';

17. WAQTD max salary and total salary of each department by considering all the employee
whose job is not ‘_’ character in it and total salary of department should be more than
5000 and should not be less then or equal to 9000.

Ans

SELECT MAX(SAL),SUM(SAL)
FROM EMP
WHERE JOB LIKE '%_%'
GROUP BY DEPTNO
HAVING SUM(SAL) > 5000 AND SUM(SAL) >= 9000

(OR)

SELECT MAX(SAL),SAL*12
FROM EMP
WHERE JOB NOT LIKE '%_%' AND SAL*12>5000 AND SAL*12<=9000
GROUP BY SAL*12;

18. WAQTD EMPLOYEE'S MANAGER NAME, JOB, COMMISSION, DEPARTMENT


NUMBER, EXISTING SALARY, NEW SALARY WITH THE REDUCTION OF 28% ONLY.
IF DEPARTMENT NUMBER EITHER 10, 20, 30 AND MANAGER HIRED AFTER 1983.

Ans

SELECT E2.ENAME,E2.JOB,E2.COMM,E2.DEPTNO,E2.SAL,E2.SAL-E2.SAL*0.28
FROM EMP E1,EMP E2
WHERE E1.MGR = E2.EMPNO AND E1.DEPTNO IN (10,20,30) AND E2.HIREDATE > '31-DEC-1983'

SQL Notes 40
19. WAQTD EMP NAME AND HIREDATE, MANAGER NAME AND HIREDATE IF
MANAGER WAS HIRED BEFORE EMPLOYEE.

Ans

SELECT E1.ENAME,E1.HIREDATE,E2.ENAME,E1.HIREDATE
FROM EMP E1,EMP E2
WHERE E1.MGR = E2.EMPNO AND E2.HIREDATE < E1.HIREDATE

20. CREATE THE FOLLOWING TABLE AS 'PRODUCTS' BY USING BELOW DETAILS.


ProdID, ProdName, Qty, Description.

Ans

CREATE TABLE PRODUCTS


(
ProdID NUMBER(4) PRIMARY KEY,
ProdName VARCHAR(10) NOT NULL,
Qty NUMBER(3) CHECK (Qty 0),
Description VARCHAR(20)
);

21. WAQTD ENAME, MANAGER'S NAME AND MANAGER'S MANAGER NAME AND WITH
THEIR LOC IF THE EMPLOYE HIRED BEFORE MARTIN AND MANAGER WORKING
IN ACCOUTING OR SALES DEPT AND MANAGER'S MANAGER EARNING SAL
MORE THAN SMITH.

Ans

SELECT E1.ENAME,E2.ENAME,E3.ENAME,D1.LOC,D2.LOC,D3.LOC
FROM EMP E1,EMP E2,EMP E3,DEPT D1,DEFT D2,DEPT D3
WHERE E1.MGR=E2.EMPNO AND E2.MGR=E3.EMPNO AND E1.DEPTNO=D1.DEPTNO AND
E2.DEFTNO=D2.DEPTNO AND E3.EMPNO=D3.DEPTNO AND
E1.HIREDATE<(SELECT HIREDATE
FROM EMP
WHERE ENAME='MARTIN') AND D2.DNAME IN ('ACCOUNTING','SALES')
AND E3.SAL>(SELECT SAL
FROM EMP
WHERE ENAME='SMITH');

22. WAQTD DETAILS OF AN EMP WHOSE NAMES STARTS WITH CHARACTER 'A' AND
'S' USING SINGLE ROW FUNCTIONS.

Ans

SQL Notes 41
SELECT *
FROM EMP
WHERE SUBSTR(ENAME,1,1) IN ('A','S');

23. WRITE A QUERY TO DISPLAY ENAME, MGR, HIREDATE, SALARY, NEW SALARY
WITH HIKE 25% FOR ALL THE EMPLOYEE. WHOSE NAME DOES NOT START WITH
A AND SORT THE RESULT IN ASCENDING ORDER WITH NEW SALARY.

Ans

SELECT ENAME,MGR,HIREDATE,SAL,SAL+SAL*0.25 NEWSAL


FROM EMP
WHERE ENAME NOT LIKE 'A%'
ORDER BY SAL+SAL*0.25 ASC;

24. WAQTD DNAME, LOC OF EMPLOYEES WHO IS GETTING 6th LEAST SAL.

Ans

SELECT DNAME,LOC
FROM DEPT
WHERE DEPTHO IN (SELECT DEPTNO
FROM EMP
WHERE SAL IN (SELECT SAL
FROM (SELECT ROWNUM SLNO, SAL
FROM (SELECT DISTINCT SAL
FROM EMP
ORDER BY SAL ASC))
WHERE SLNO-6));

25. WAQTD DETAILS OF THE EMPLYOEES AND THEIR MANAGER'S JOB AND
MANAGER'S MANAGER MGR ALONG WITH THEIR LOCATIONS IF EMPLOYEES
GETTING MORE THEN 2700 AND MANAGER WORKING EITHER IN DEPTNO. 10,20
AND MANAGER'S MANAGER WORKING IN IN ACCCOUNTING AND RESEARCH.

Ans

SELECT E1.*,E2.JOB,E3.MGR,D1.LOC,D2.LOC,D3.LOC
FROM EMP E1,EMP E2,EMP E3,DEPT D1,DEPT D2,DEPT D3
WHERE E1.MGR=E2.EMPNO AND E2.MGR=E3.EMPNO AND E1.DEPTNO=D1.DEPTNO AND
E2.DEPTNO=D2.DEPTNO AND E3.DEPTNO=D3.DEPINO AND E1.SAL>2700 AND
E2.DEPTNO IN (10,20) AND D3.DNAME IN ('ACCOUNTING','RESEARCH');

SQL Notes 42
28. WAQTD ALL DETAILS OF EMP ALONG WITH ANNUAL SAL, IF THEY ARE WORKING
IN DEPT 10 OR 20, HIRED IN THE MONTH OF SEPT AND EARNS MORE THAN 2000
AND WORKING AS PRESIDENT

Ans

29. WAQTD SALARIES WHICH ARE REPEATED IN EMP TABLE

Ans

30. WAQTD NAMES OF EMP GETTING SALARY MORE THAN SMITH IN NEWYORK

Ans

31. WAQTD EMP NAME, MANAGERS NAME AND HIS MANAGERS NAME, ALONG WITH
THEIR LOCATION IF EMP IS EARNING MORE THAN SMITH, MANAGER WORKING
IN SAME DEPT AS THAN OF JONES AND MANAGERS MANAGER WORKING IN
NEW YORK

Ans

32. WAQTD NAMES OF EMP GETTING 25TH MAX SAL

Ans

33. WAQTD NAMES OF EMPLOYEE HAVING EXACTLY 2 A's IN HIS NAME

Ans

34. WAQT RENAME COLUMN FROM SID TO ID

Ans

35. WAQTD DETAILS OF EMP'S HIRED IN THE YEAR 81,83,87

Ans

SQL Notes 43
36. WAQTD 3RD MINIMUM SALARY

Ans

37. WAQTD ENAME, MANAGER'S NAME AND THEIR LOC IF EMP WORKING IN DEPT
10 OR 30 AND MANAGER EARNING MORE THAN FORD AND EMP WORKING IN
LOC NEW YORK OR CHICAGO

Ans

38. WAQTD THE ENAME'S WHICH ARE REPEATED IN EMP TABLE ?

Ans

39. WAQTO NAMES OF EMPLOYEES HIRED AFTER 81 AND BEFORE 87 ?

Ans

40. WAQTD NAME AND SAL OF THE EMPLOYEES EARNING MORE THAN KING IN THE
DEPT ACCOUNTING ?

Ans

41. WAQTD DETAILS OF EMP'S IF THEIR NAME STARTS WITH A' or 'S' USING SRF ?

Ans

42. WAQTD all details of emp along with annual salary. if employee is working as president
or analyst and hired in month of September ?

Ans

43. WAQTD names of employee earning salary more then smith in same department as that
of KING ?

Ans

SQL Notes 44
44. WAQTD employee names, managers names along with their location of emp is earning
more then SCOTT and manager working in DALLAS ?

Ans

45. WAQTD name of employee getting 26th max salary ?

Ans

46. WAQTD details of employee whose name starts with VOWELS ?

Ans

47. WAQTD details of employee hired in Leap year ?

Ans

48. WAQTD bottom 5 more salaries ?

Ans

49. WAQTD Ename, Sal, Deptno, Dname of the employee of their name having character ‘A’
in it ?

Ans

50. WAQTD Dname who are reporting to KING ?

Ans

51. WAQTD SMITH manager’s manager name ?

Ans

52. WAQTD Department name of employee who are getting salary more then KILLER ?

Ans

SQL Notes 45
53. WAQTD number of employee’s hired after 82 but they are getting some salary as
FORD’S salary ?

Ans

54. WAQTD number of employee working in each department in which there are atmost 5
employee are working ?

Ans

55. WAQTD ENAME, DNAME ONLY IF THE DNAME IS HAVING ATLEAST ONE ‘O’ OF
THE DNAME AND THE EMPLOYEE IS HAVING ‘E’ AS THE
SECOND LAST CHARACTER ?

Ans

56. WRITE A QUERY TO DISPLAY ENAME, MGR, HIREDATE, SALARY, NEW SALARY
WITH HIKE 25% FOR ALL THE EMPLOYEE WHOSE NAME DOES NOT START WITH
A AND SORT THE RESULT IN ASCENDING ORDER WITH NEW SALARY.

Ans

57. WAQTD ENAME,MANAGER'S NAME AND MANAGER'S MANAGER NAME AND WITH
THEIR LOC IF THE EMPLOYE HIRED BEFORE MARTIN AND MANAGER WORKING
IN ACCOUTING OR SALES DEPT AND MANAGER'S MANAGER EARNING SAL
MORE THAN SMITH.

Ans

58. WAQTD DNAME AND EMPNO FOR ALL THE EMPLOYEES WHO'S EMPNO ARE
(7839,7902) AND ARE WORKING IN LOC NEW YORK.

Ans

SQL Notes 46
59. DISPLAY ALL THE EMPLOYEES WHOSE NAME START WITH 'S' AND HAVING
SALARY
MORE THAN 'ALLEN' AND LESS THAN FORD.

Ans

60. WAQTD THE DNAME OF THE EMPLOYEE WHO IS GETTING 7TH MINIMUM SALARY
?

Ans

61. WAQTD ENAME, DNAME ONLY IF THE DNAME IS HAVING ATLEAST ONE ‘O’ OF
THE DNAME AND THE EMPLOYEE IS HAVING ‘E’ AS THE SECOND LAST
CHARACTER ?

Ans

62. DISPLAY ENAME, DNAME OF ALL THE EMPLOYEES WHOSE SALARY LESS THAN
AVG SAL OF DEPT 30.

Ans

63. WRITE A QUERY TO DISPLAY EMPLOYEE NAME, JOB, COMMISSION,


DEPARTMENT NUMBER, EXISTING SALARY, NEW SALARY WITH THE REDUCTION
OF 35% ONLY
IF JOB NOT EQUAL TO CLERK AND DEPARTMENT NUMBER EITHER 10, 20, 30
AND HIREDDATE GREATER THAN 1983.

Ans

64. WRITE A QUERY TO DISPLAY EMPLOYEE NAME, JOB, DNAME, LOCATION OF ALL
EMPLOYEES WHO ARE WORKING AS ACTUAL MANAGERS AND WORKS AT
CHICAGO.

Ans

SQL Notes 47
65. LIST THE DEPARTMENT NAMES IN WHICH THE EMPLOYEES ARE HIRED
BETWEEN 1ST OF JAN 1981 AND 31ST DEC 1982 WITH SALARY MORE THAN 1800.

Ans

66. WAQ TO CONSTRUCT A TABLE(STUDENT) THAT CAN ACCEPT


A. SID
B. SNAME
C. SBRANCH
D. SPERCENTAGE

Ans

67. WAQTD EMPLOYEE NAME AND MANAGERS COMM IF EMPLOYEE WORKS AS


SALESMAN AND MANAGERS WORKS IN DEPTNO 30.

Ans

68. DISPLAY ALL THE EMPLOYEES WHOSE NAME START WITH 'S' AND HAVING
SALARY
MORE THAN 'ALLEN' AND LESS THAN FORD.

Ans

69. DISPLAY EMPNO, ENAME, JOB, WHOSE JOB HAS 'E' IN IT AND DISPLAY EMPNO IN
DESCENDING ORDER.

Ans

70. WAQTD 4th max salary from emp table?

Ans

71. WAQTD dname of an employee getting 2nd max salary ?

Ans

SQL Notes 48
72. WAQTD Ename start with VOWELS (A.E.I.O.U) ?

Ans

73. WAQTD all the details along with annual salary of employee who are working in location
CHICAGO or NEW YORK ?

Ans

74. Create a table with name “product” having columns like (PID, Pname, Price, Discount
)and insert any 2 records using any of the syntex ?

Ans

75. WAQTD max salary of an emp working in each dept having at least 2 employees in each
dept ?

Ans

76. WAQTD Ename, manager Ename, Emp dname and managers dname where emp
working in deptno 10 and manager working in location CHICAGO ?

Ans

77. WAQTD Ename and dname of all the employees ?

Ans

SQL Notes 49

You might also like