Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Exam (elaborations)

SQL interview questions

Rating
-
Sold
-
Pages
6
Grade
A
Uploaded on
08-02-2024
Written in
2023/2024

This document is intended for anyone seeking for the job opportunity. It contains the most frequently asked interview questions I experienced.

Institution
Course

Content preview

SQL interview questions:

Q1. If month in between jan and jul then 2022 else 2023. What function used to find and how?
select *, case when month between jan and july then 2022 else 2023 end as year from tablename;


Q2. how to get the maximum among two tables,for example table 1 (dep1) have (emp_id,emp_name,salary)
columns and table 2 (dept2) have (emp_id,emp_name,salary) columns,i want which employee have the
maximum salary among two tables?
SELECT MAX(Salary) FROM
(SELECT MAX(Salary) as Salary FROM dep1
UNION
SELECT MAX(Salary) as Salary FROM dep2) E


Q3. Is a NULL value same as zero or a blank space? If not then what is the difference?
 zero or blank space can be compared with another zero or blank space. whereas one null may not be
equal to another null.
 A null value is not the same as a blank space or a zero value. A zero value is an integer and a blank
space is a character while a null value is the one that has been left blank.
Q4. DROP command used for?
If you drop a table, all the rows in the table is deleted and the table structure is removed from the database.
Once a table is dropped we cannot get it back, so be careful while using DROP command.
Q5. Find the 3rd highest salary using window functions?
SELECT * FROM (
SELECT emp_name, emp_salary, DENSE_RANK() OVER (ORDER BY emp_salary DESC) AS r
FROM emp
) AS subquery
WHERE r = 3;
OR
SELECT emp_name, salary, ROW_NUMBER()
OVER(ORDER BY salary DESC) AS 3rd_highest_salary
FROM employee where 3rd_highest_salary =3;


Q6. How to get only duplicate records?
Select col1, COUNT(col1) as count from tablename group by col1 having count(col1)>1 ;


Q7. Write a query to fetch only the place name(string before brackets ie Toronto) from the city column of
EmployeeDetails table.

, EmpId, FullName ManagerId DateOfJoining City
121 John Snow 321 01/31/2014 Toronto(TR)
321 Walter White 986 01/30/2015 New York(NY)
421 Kuldeep Rana 876 27-11-2016 New Delhi(DL)


SELECT left(city, CHARINDEX('(','City') -1) as city from Employee;


Q8. Write the query for the following input.
Source:
Sno name sal
1 a 5000
2 b 3000
3 c 2000
Target:
Sno Name Sal Sal_diff
1 a 5000 0
2 b 3000 2000
3 c 2000 3000
select Sno, Name, Sal, (select max(Sal) as max from source) - Sal as Sal_diff from source;

Q9. Write the query for the following input.
Email







separate name and domain

name domain

xyz gmail.com

abc yahoo.in

qwe outlook.com

select left(Email, CHARINDEX('@',Email) -1) as name, substring(Email, CHARINDEX('@',Email) +1), LENGTH(Email)) as
domain from emp;

Written for

Course

Document information

Uploaded on
February 8, 2024
Number of pages
6
Written in
2023/2024
Type
Exam (elaborations)
Contains
Questions & answers

Subjects

$8.49
Get access to the full document:

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Get to know the seller
Seller avatar
rbabyshri

Get to know the seller

Seller avatar
rbabyshri Exam Questions
Follow You need to be logged in order to follow users or courses
Sold
-
Member since
2 year
Number of followers
0
Documents
2
Last sold
-

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions