0% found this document useful (0 votes)
39 views5 pages

Essential SQL Interview Questions Guide

The document discusses several SQL interview questions and concepts: 1) How to find the second highest salary and Nth highest salary from a table using MAX, LIMIT, and ORDER BY. 2) How to delete duplicate rows from a table by removing rows with non-minimum IDs for each name. 3) The differences between DELETE, TRUNCATE, and DROP - how they remove rows and whether the operations can be rolled back. 4) The concept of a many-to-many relationship between tables and how to query courses joined by a particular student.

Uploaded by

venkateshgavini
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)
39 views5 pages

Essential SQL Interview Questions Guide

The document discusses several SQL interview questions and concepts: 1) How to find the second highest salary and Nth highest salary from a table using MAX, LIMIT, and ORDER BY. 2) How to delete duplicate rows from a table by removing rows with non-minimum IDs for each name. 3) The differences between DELETE, TRUNCATE, and DROP - how they remove rows and whether the operations can be rolled back. 4) The concept of a many-to-many relationship between tables and how to query courses joined by a particular student.

Uploaded by

venkateshgavini
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

SQL Interview Questions:

[Link] Second Highest:

select max(sal) From emp where sal NOT IN (select max(sal) from emp);
select * from emp order by sal desc limit 1,1;(starting from 1(2nd record) to 1 record to
retrieve)

[Link] Nth Highest:

select * from emp order by sal desc limit n-1,1;


select id,name,max(sal) from salary a where 2 = (select count(*) from salary b where
[Link]>[Link])

[Link] Duplicate Rows from a Table.

delete from dummy where id not in(select min(id) from dummy group by name)

[Link] between Delete, Truncate and Drop.

The DROP command removes a table from the database. All the tables' rows, indexes
and privileges will also be removed. ... DROP and TRUNCATE are DDL commands,
whereas DELETE is a DML command. Therefore DELETE operations can be rolled
back (undone), while DROP and TRUNCATE operations cannot be rolled back.
TRUNCATE Removes all rows from a table or specified partitions of a table, without
logging the individual row deletions. TRUNCATE TABLE is similar to the DELETE
statement with no WHERE clause; however, TRUNCATE TABLE is faster and uses
fewer system and transaction log resource.
[Link] between DBMS and RDBMS.

[Link] to Many RelationShip Entire Concept:

Table : Stu
Table : stucourse(It acts as a RelationShip between two Tables).

Table: Course

(i)Query:

Retrive the courses that are Joined by the Mike.

select [Link],[Link]

from stu a, course b, stucourse c

where [Link]=[Link] and [Link]=[Link] and [Link]='Mike'

Output:
2nd Query:

Retrive count of all the Courses that are Joined by each student:

select [Link], count(*) as courses


from stu a, course b, stucourse c
where [Link]=[Link] and [Link]=[Link]
group by [Link]

Difference between Union And Union All


Union doesnt allows the Duplicates, But Union All will allow the Duplicates in the Result
Set.
View:

You might also like