What does SELECT MIN(+ - Column) do?

Eric S 07/11/2018 at 19:28. 1 answers, 184 views
sql-server sql-server-2014

I ran into a query today that did something I haven't seen before. It did something like this:

SELECT 
    MIN(+ - schema_id) AS [WhatInTheWorld?], 
    MIN(schema_id) AS MinimumID, 
    MAX(+ - schema_id) AS [Uhhh], 
    MAX(schema_id) AS MaxID
FROM sys.objects

Which gives the following results:

WhatInTheWorld? MinimumID    Uhhh       MaxID
-4              1            -1         4

What exactly are the "+" and "-" doing?

1 Answers


ypercubeᵀᴹ 07/11/2018 at 19:39.

MIN(+ - schema_id) is parsed as MIN(- schema_id), so it's the same as -MAX(schema_id). Likewise for the MAX.

Related questions

Hot questions

Language

Popular Tags