max function and where clause

  • Hi,

    I went to retrive the the maximum of one cloumn in the table meet some where criteria. I tried the folowing SQL

    Select Name, Max(version) from table1 where name="Asdf";

    I am unable to get the required result set which I need from above query.

    Can you please tell me what is wrong with the query?

    Thank you!

  • grasshopper26 (4/12/2013)


    Hi,

    I went to retrive the the maximum of one cloumn in the table meet some where criteria. I tried the folowing SQL

    Select Name, Max(version) from table1 where name="Asdf";

    I am unable to get the required result set which I need from above query.

    Can you please tell me what is wrong with the query?

    Thank you!

    Select Name, Max(version) from table1 where name="Asdf" group by Name;

  • Either of these:

    SELECT Name, MAX(version) OVER(PARTITION BY Name)

    FROM table1

    WHERE name = 'Asdf';

    SELECT Name, MAX(version)

    FROM table1

    WHERE name = 'Asdf'

    GROUP BY Name;

    Avoid doublequotes, they have a special meaning to SQL Server.

    “Write the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.” - Gail Shaw

    For fast, accurate and documented assistance in answering your questions, please read this article.
    Understanding and using APPLY, (I) and (II) Paul White
    Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply