Select NULL AS Max or Min in SQL Query

Bradley Schacht

Bradley Schacht is a Cloud Solution Architect on the state and local government team with Microsoft based in Jacksonville, FL. He has co-authored 3 SQL Server books including "SQL Server 2014 Professional Administration". As a former consultant and trainer, he uses his experience on many parts of the Microsoft BI and data platform to help customers deliver the best possible solutions. Bradley frequently presents at community events around the country. He is a contributor to sites such as and an active member of the Jacksonville SQL Server User Group (JSSUG).

You may also like...

4 Responses

  1. McOz says:

    Starting in SQL 2005, you could simply use:

    NULLIF(MAX(COALESCE(EndDate, ’12/31/2099′)),’12/31/2099′) AS Date

  2. Hilda says:

    Great article, this is exactly what I was looking for.

  3. Amy-Etymotic Research says:

    This is related to an issue I am currently having. I have a table with contact info and a table with their orders. ID # on the contacts is linked to the orders customer # as a one to many relationship. (One contact can have many orders).

    I built a query with the contact and orders tables, grouped by the linked customer number in orders and made a max order date field.

    When I changed my form to display from this query, I lost all my opportunity accounts–those with no max order date. I also lost the ability to add new records.

    How can I make the query show ALL records even those with no orders and therefore no max order date?

    Thank you.

  4. Thank you, this is what I was looking for.

Leave a Reply