Search code examples
mysqllimit

First value without LIMIT


I like to get the first and last name of the last member(s) who signed up without using LIMIT clause in MYSQL. The following code works but my assignment asks me to write the code without LIMIT.

SELECT firstname, surname
FROM Members
ORDER BY joindate DESC
LIMIT 1

Solution

  • Use a WHERE clause to return only the row(s) with the latest joindate:

    SELECT firstname, surname
    FROM Members
    WHERE joindate = (SELECT MAX(joindate) FROM Members)