Is there a solution for the error, result of select more than one row?
By submitting your email address, you agree to receive emails regarding relevant topic offers from TechTarget and its partners. You can withdraw your consent at any time. Contact TechTarget at 275 Grove Street, Newton, MA.
The description of the problem is a little vague, but I'm going to guess the query has a scalar subquery that is actually returning more than one row --
select foo, bar from fubar where bar = ( select baz from qux )
In this example, the subquery must return exactly one value, or else the outer query fails. This cannot be checked by the database until execution time. Depending on what is required, there are a couple of ways to rewrite the query --
select foo, bar from fubar where bar = ( select min(baz) from qux )
Using an aggregate function like min() will always return only one value.
select foo, bar from fubar where bar IN ( select baz from qux )
Here the subquery is no longer a scalar or single value subquery, but the outer query will not fail if more than one value is returned.
For More Information
- What do you think about this answer? E-mail the edtiors at editor@searchDatabase.com with your feedback.
- The Best SQL Web Links: tips, tutorials, scripts, and more.
- Have an SQL tip to offer your fellow DBAs and developers? The best tips submitted will receive a cool prize. Submit your tip today!
- Ask your technical SQL questions -- or help out your peers by answering them -- in our live discussion forums.
- Ask the Experts yourself: Our SQL, database design, Oracle, SQL Server, DB2, metadata, object-oriented and data warehousing gurus are waiting to answer your toughest questions.
Have a question for an expert?
Please add a title for your question
Get answers from a TechTarget expert on whatever's puzzling you.