Skip to content
Advertisement

Use Aggregate Function in UNION ALL result set

How can I use aggregate Functions in UNION ALL Resultset

FOR EXAMPLE

Result Set Would Be

When I tried to get MAX(A) it returns 3. I want 6.

When I tried to get MAX(B) it returns 4. I want 7.

Other than Max(), Can I get another aggregate function which user defined?

For example:

(SELECT TOP 1 A WHERE B=5)

Real Case Here

Advertisement

Answer

Try this way:

SQL Fiddle DEMO

If the column A is varchar (You said that in the comment below) try this way:

With TOP 1

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