none
SELECT MIN

    Question

  • This code:

    SELECT * FROM tblBooks WHERE ID=MIN(ID);
    

    Results in the error shown below

    An aggregate may not appear in the WHERE clause unless it is in a subquery contained in a HAVING clause or a select list, and the column being aggregated is an outer reference.

    Being relatively new at this I'm not sure exactly how to fix it, I am simply trying to find and use a minimum ID number in a table.

    Milt


    sirmilt

    Monday, November 04, 2013 5:24 PM

Answers

  • try,

    SELECT * FROM tblBooks WHERE ID= (select MIN(ID) from tblBooks);


    Please use Marked as Answer if my post solved your problem and use Vote As Helpful if a post was useful.

    • Proposed as answer by Saeid Hasani Monday, November 04, 2013 5:51 PM
    • Marked as answer by sirMilt Tuesday, November 05, 2013 3:55 PM
    Monday, November 04, 2013 5:29 PM

All replies

  • try,

    SELECT * FROM tblBooks WHERE ID= (select MIN(ID) from tblBooks);


    Please use Marked as Answer if my post solved your problem and use Vote As Helpful if a post was useful.

    • Proposed as answer by Saeid Hasani Monday, November 04, 2013 5:51 PM
    • Marked as answer by sirMilt Tuesday, November 05, 2013 3:55 PM
    Monday, November 04, 2013 5:29 PM
  • Thank you, Saeid, it worked exactly as I had hoped.

    Milt


    sirmilt

    Tuesday, November 05, 2013 3:55 PM