Question
Given the following tables: Orders (OrderID,
CustomerID, OrderDate) and Customers (CustomerID, CustomerName, City), what SQL query will return the names of customers who have placed orders in 'New York' within the last 30 days?Solution
The correct query utilizes a JOIN between the Customers and Orders tables on the CustomerID field. This allows you to filter customers who are located in 'New York' and have placed an order in the last 30 days. The JOIN ensures that only customers who have an associated order are included, and the date condition (OrderDate >= CURDATE() - INTERVAL 30 DAY) filters for recent orders. Why Other Options Are Wrong : A) Incorrect : The query attempts to filter customers directly, but it fails to include the necessary JOIN with the Orders table, which is crucial for retrieving orders placed by customers in 'New York'. C) Incorrect : This query incorrectly selects from the Orders table and does not filter by customer details. The City column does not exist in the Orders table. D) Incorrect : This query incorrectly attempts to select data from the Customers table without joining it with the Orders table, so there will be no filtering by order date. E) Incorrect : Although the JOIN is correctly applied, this query places the conditions in the wrong order, and the query logic would still be correct but unnecessarily complex.
Consider the following statements about ozone layer:
1. It protects us from UV rays.
2. It is found in the troposphere.
3. CFCs are harmful to it.
Which state was declared India’s first fully literate state in 2025?
- Which article of the Indian Constitution addresses the Governor's Pardoning Power?
Who was re-appointed as the Managing Director and CEO of Central Depository Services (India) Limited (CDSL) in August 2024?
Which of the following is NOT an advantage of privatization?
Which ministries collaborated to organize the Veer Gatha 3.0 event in New Delhi?
Which state has the country’s first Graphene Innovation Centre?
AU Small Finance Bank has partnered with Mastercard for the official launch of the Mastercard Debit Card, specifically catering to the bank's corporate ...
When is 'World Water Day' celebrated every year to highlight the importance of water?
Which ministry will implement the PM Vidyalaxmi scheme?