0% found this document useful (0 votes)
15 views8 pages

Adbms 1.4

Uploaded by

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

Adbms 1.4

Uploaded by

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

ADBMS LAB

EXPERIMENT
1.4

Student Name: Akash Raj Subject Code:

22CAP637 UID: 22MCI10178 Section/Group:

22MAM-2_B

Semester: 1st Semester Date of Performance: 06/11 /22

Task to be
done:
EmployeeInfo
Table:
EmpID EmpFname EmpLname Department Project Address DOB Gender
1 Sanjay Mehra HR P1 Hyderabad(H 01/12/197 M
YD 6
)
2 Ananya Mishra Admin P2 Delhi(DEL) 02/05/196 F
8
3 Rohan Diwan Accoun P3 Mumbai(BOM) 01/01/198 M
t 0
4 Sonia Kulkar HR P1 Hyderabad(H 02/05/199 F
ni YD
) 2
5 Ankit Kapoo Admin P2 Delhi(DEL) 03/07/199 M
r
4
EmployeePosition Table:
EmpI EmpPositio DateOfJoinin Salary
D n g
1 Manager 01/05/2022 500000
2 Executive 02/05/2022 75000
3 Manager 01/05/2022 90000
2 Lead 02/05/2022 85000
1 Executive 01/05/2022 300000
Let us start by taking a look at some of the most frequently asked SQL Query
interview questions,

a) Write a query to fetch the EmpFname from the EmployeeInfo table in the upper
case and use the ALIAS name asEmpName.
b) Write a query to fetch the number of employees working in the department ‘HR’.
c) Write a query to get the cur ent date.
d) Write a query to retrieve the first four characters of EmpLname from the EmployeeInfo
table.
e) Write a query to fetch only the place name(string before brackets) from the Address
column of EmployeeInfo table.
f) Write a query to create a new table that consists of data and structure copied from the
other table.
g) Write q query to find all the employees whose salary is between 50000 to 100000.
h) Write a query to find the names of employees that begin with ‘S’
i) Write a query to fetch top N records.
j) Write a query to retrieve the EmpFname and EmpLname in a single column as
“FullName”. The first name and thelast name must be separated with space.

I’ve used online compiler of programiz.com for all question except for the part (c)
and (j) for these I've used XAMMP MYSQL as these two commands are showing the
error that sysdate() and concat() -> no such function exist.
Solution of part (a):

Query to fetch EmpFname from

EmployeeInfo table - select

upper(EmpFname) as EmpName from

EmployeeInfo;Output of the query:

Solution of part (b):

Query to fetch no of employee in HR dept from EmployeeInfo table -

select count(*) from EmployeeInfo where dept

= ‘HR’;Output of the query:

Solution of part (c):

Query to fetch the date from system (by using XAMPP / MYSQL) -

select sysdate();

Output of the

query:
Solution of part (d):

Query to fetch the first four character from EmployeeInfo table -

Select substring(EmpLname, 1, 4) from

EmployeeInfo;Output of the query:

Solution of part (e):

Query to fetch the first four character from

EmployeeInfo table - Select substring(address, 1,

charindex(‘(’, adress)) from EmployeeInfo;Output

of the query:

Solution of part (f):


Query to create a new table which consist the data and structure of EmployeeInfo
table -

Create table NewTable as select *

from EmployeeInfo;select * from

NewTable; Output of the query:

Solution of part (g):

Query to fetch the data of employees whose salary is 50000 to


100000 from employyePostion table -

select * from EmployyePosition where salary between ‘50000’ and

‘100000’;Output of the query:

Solution of part (h):

Query to fetch the data of employees whose names begins with ‘S’ -

select * from EmployyePosition where

empfname like ‘S%’;Output of the


query:
Query to fetch the data of top N records -

select top N * from EmployyePosition where

order by salary desc;N – any number

from the table.

Output of the query:

Note-This will not generate output until we define the N to a limit. If we


execute this statement as it is it’llgive a syntax error.

Solution of part (j):

Query to fetch the data from two columns and make

show it as one - select concat(empfname, ‘

’,emplname) as ‘Fullname’ from

Employeeinfo;Output of the query:


Learning Outcome
a. Usage of Upper() function to convert text to upper-case.
b. Usage of count(*) function to count all the entities according to the condition.
c. Usage of three functions curdate(), sysdate(), getdate() to get the date and time
in the sql only work onMysql installed system not in Online Compilers like
LiveSQL.
d. Usage of substring() method to extract substrings from the text.
e. Creation of New table using as and passing select as a condition.
f. Usage of between operator from the name its clear, it selects the values
within the given range.
g. Usage of % and like operator to fetch the data from the table.
h. Usage of Top method to specify the number of record to return -> this comes
in handy if we are dealingwith the large tables having thousands of records.
i. Usage of concat() function to add two strings as we did empfname and
emplname into a single column asfullname.

Evaluation Grid:

Sr. No. Parameters Marks Obtained Maximum Marks


1. Demonstration and 5
Performance
(Pre Lab Quiz)
2. Worksheet 10
3. Post Lab Quiz 5

You might also like