Top 10 Complex Sql Queries Interview Questions You Must Prepare 27.Jul.2024

Q1. What Is The Query To Fetch Last Record From The Student Table?

SELECT * FROM Student order by id desc limit 1

Q2. What Is The Query To Fetch First Record From Student Table?

SELECT * from Student where id = 1;

Q3. What Is Query To Display Nth Record From Student Table?

Select * from Student  where id = $n;

Q4. Query To Find Duplicate Rows In Table?

SELECT std_id, COUNT(std_id) as cnt FROM Student GROUP by std_id having cnt > 1

Q5. How To Display Odd Rows In Student Table?

SELECT * FROM Student where MOD(id,2) = 1

Q6. How Can I Create Table With Same Structure Of Student Table?

Create table std as Select * from Student;

Q7. Query To Find Second Highest Marks Of A Student?

Based On the Below Student table We are Written All the Queries.

Student Table

SELECT marks FROM Student ORDER by marks DESC limit 1, 1;

Q8. How To Display Even Rows In Student Table?

SELECT * FROM Student where MOD(id,2) = 0

Q9. What Is Query To Display Last 3 Records From Student Table?

SELECT *  FROM Student order by std_id Desc limit 3

Q10. How To Get 3 Highest Marks From Student Table?

SELECT distinct(marks) FROM Student ORDER BY marks DESC LIMIT 0,3