Database
Aptitude · Reasoning · English · CS — Corporate & Campus Interview Prep
12 Questions 10 Topics Take Test
Advertisement
Showing 11–12 of 12 questions
Q.11 Hard SQL Basics
For optimizing a complex query joining 5 tables with WHERE conditions, what is the recommended approach?
A Always use INNER JOINs first, then add WHERE conditions
B Use indexes on join columns and filter columns, check execution plan, simplify subqueries
C Rewrite as multiple simple queries and combine in application
D Use VIEW instead of direct query
Correct Answer:  B. Use indexes on join columns and filter columns, check execution plan, simplify subqueries
Explanation:

Proper indexing on join and filter columns is crucial. Analyzing execution plan identifies bottlenecks. Application-level combining is inefficient. VIEWs don't inherently optimize.

Take Test
Q.12 Hard SQL Basics
In a manufacturing database, to find products with sales in ALL regions, which approach is correct?
A SELECT product_id FROM sales GROUP BY product_id HAVING COUNT(DISTINCT region) = (SELECT COUNT(*) FROM regions)
B SELECT product_id FROM sales WHERE region IN (SELECT DISTINCT region FROM sales)
C SELECT DISTINCT product_id FROM sales s1 WHERE region = 'North' AND EXISTS (SELECT 1 FROM sales WHERE product_id = s1.product_id)
D SELECT product_id FROM sales WHERE region = 'North' OR region = 'South'
Correct Answer:  A. SELECT product_id FROM sales GROUP BY product_id HAVING COUNT(DISTINCT region) = (SELECT COUNT(*) FROM regions)
Explanation:

Counts distinct regions per product and compares to total regions. Option B doesn't ensure ALL regions. Option C only checks one region. Option D is incomplete.

Take Test
IGET
IGET AI
Online · Exam prep assistant
Hi! 👋 I'm your iget AI assistant.

Ask me anything about exam prep, MCQ solutions, study tips, or strategies! 🎯
UPSC strategy SSC CGL syllabus Improve aptitude NEET Biology tips