Skip to content
Advertisement

SQL case return more than 1 row write a string

I have a subquery in SELECT and sometimes it returns more than one row. I want to solve the problem like this:

  • when more than 1 row write a string like ‘multi’
  • otherwise use the value description from comment table

Query:

thanks.

Advertisement

Answer

You can join, aggregate, and use a conditional expression:

You can also do this with a subquery, which avoids outer aggregation (it is handy if you need more columns from students):

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement