Explain what this SQL query does and how it works.
💡 Model Answer
The query retrieves the top two product names by total revenue. It joins Table1 (sales data) with Table2 (product details) on product_id. For each product, it sums the product of quantity and unit_price from Table1 to calculate revenue. The GROUP BY t2.product_name aggregates the revenue per product. ORDER BY SUM(t1.quantity * t1.unit_price) DESC sorts products from highest to lowest revenue. Finally, LIMIT 2 returns only the first two rows of that sorted list. In short, it lists the two best‑selling products by revenue.
This answer was generated by AI for study purposes. Use it as a starting point — personalize it with your own experience.
🎤 Get questions like this answered in real-time
Assisting AI listens to your interview, captures questions live, and gives you instant AI-powered answers on a discreet on-screen overlay.
Get Assisting AI — Starts at ₹500