SQL questions asked in top product based companies:

murali krishna
3 min readSep 9, 2023

--

Question 1:

Imagine a table named “Movies” with columns: MovieID, Title, ReleaseDate, GenreID.

There’s another table “Genres” with columns: GenreID, GenreName.

Write a SQL query to fetch the genres that don’t have any movies associated with them.

Question 2:

You are given a table named “Attendance” with columns: StudentID, ClassDate, IsPresent

(A Boolean where ‘True’ indicates presence and ‘False’ indicates absence).

Write a SQL query to identify students who have missed more than 3 consecutive classes.

Question 3:

Consider a table named “Elections” with columns: CandidateID, VoterID, VoteDate. Write a SQL query to calculate the candidate who received the highest number of votes each month.

Question 4:

You are provided with a table named “LibraryBooks” with columns: BookID, BorrowerID, BorrowDate, ReturnDate.
Write a SQL query to find out which books are currently borrowed and have passed their return date without being returned.

Question 5:

Consider a table named “OnlineCourses” with columns: CourseID, EnrollmentDate, StudentID, CompletionDate. Write a SQL query to determine the courses which have the highest drop rate (i.e., students enrolling but not completing).

Question 6:

You have a table named “EmployeeFeedback” with columns: EmployeeID, FeedbackDate, Rating (from 1 to 10).
Write a SQL query to identify employees whose rating has been declining for the past 3 consecutive feedbacks.

Question 7:

There are two tables: “BlogPosts” and “Comments”. The “BlogPosts” table has columns: PostID, Title, PostDate, AuthorID.

The “Comments” table has columns: CommentID, PostID, CommentDate, Text.

Write a SQL query to fetch the blog posts that have not received any comments within a week of their posting.

Question 8:

Consider a table named “TouristSpots” with columns: SpotID, SpotName, VisitorID, VisitDate. Write a SQL query to find the least visited tourist spots in the last summer.

Question 9:

There are two tables: “Books” and “Authors”.

The “Books” table has columns: BookID, BookName, AuthorID, SoldCopies. The “Authors” table has columns: AuthorID, AuthorName.

Write a SQL query to find authors whose books, on average, have sold more than 10,000 copies, but have written less than 3 books.

Question 10:

You have a table named “FlightBookings” with columns: BookingID, FlightDate, PassengerID, Destination.

Write a SQL query to determine which destination has seen a steady month-on-month increase in bookings over the last year.

--

--