Tuhin Paul
How can you modify the subquery to return a single value?

How can you modify the subquery to return a single value?
A) Add a GROUP BY clause to the subquery.
B) Add a TOP 1 clause to the subquery.
C) Add a DISTINCT clause to the subquery.

By Tuhin Paul in .NET on Apr 15 2023
  • Jay Pankhaniya
    Apr, 2023 29

    The correct answer is B) Add a TOP 1 clause to the subquery.

    To modify a subquery to return a single value, you can use the TOP 1 clause in the subquery to limit the result set to a single row. This will ensure that the subquery returns only one value, which can then be used in the outer query.

    For example, consider the following query:

    1. SELECT name FROM customers WHERE customer_id = (SELECT customer_id FROM orders WHERE order_total > 1000)

    If the subquery returns multiple customer_id values, the error “Subquery returned more than 1 value” will be thrown. To fix this, you can modify the subquery as follows:

    1. SELECT name FROM customers WHERE customer_id = (SELECT TOP 1 customer_id FROM orders WHERE order_total > 1000)

    • 0


Most Popular Job Functions


MOST LIKED QUESTIONS