SQLTeam.com | Weblogs | Forums

What does MIN(*) do?

Hello

What does MIN(*) do?

It does not seem to make sense. The * would mean that all the columns in the table are returned so how can the MIN(*) make sense if even some columns are not numbers?

Thanks

Hello

You will get better answer if you read and fully understand the details from the creator of the MIN function

but here is one hint

ALL
Applies the aggregate function to all values. ALL is the default.

1 Like

Thanks but not sure I can find that detail in the article.

A MIN(*) in the table below will return 1?
A, 2, 5
B, 3, 1
B, 5, 4

And a HAVING MIN(*)>1 will return A?

If you are using SQL Server, this is not valid. You will get a syntax error if you try to parse it or run it.

To what yosiaz was referring, this is from the documentation:

Expression (in the brackets) is a constant, column name, or function, and any combination of arithmetic, bitwise, and string operators. MIN can be used with numeric , char , varchar , uniqueidentifier , or datetime columns, but not with bit columns. Aggregate functions and subqueries are not permitted.

1 Like

you can if you read it all and experimented with what it says using the data you have. So are you using Microsoft SQL server? Also are you trying to solve a problem or just trying to understand MIN? If you are trying to solve a problem please provide sample data and the expected result you would like to see. @harishgg1 has already provided you a nice answer on MIN. But you are still asking so there must be something you have not been able to solve or not able to understand. But we will need some real world data or something close to it, to help you understand this MIN thing.

Thanks, I only need to know what is the meaning of

SELECT * FROM TABLE HAVING MIN(*)>1

sqlor

I will try to answer your question
Tomorrow

It's my bed time

Maybe some experts on the forum will
Be able to
Before me

it has no meaning in SQL Server because it is not a proper SQL statement.

What system is that code coming from? If that is coming from Oracle then you need to ask in an Oracle forum what that is doing and how it works.

As stated by others - that syntax is not valid in SQL Server and HAVING is generally used with a GROUP BY, but without a GROUP there is an implicit single aggregate group.

That statement will fail in SQL Server on the MIN(*) - and if you specify a column in the MIN then it will fail on the * in the SELECT because that column is invalid in the select list because it is not contained in either an aggregate or group by.