Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in SQL by (20.3k points)

How would I do something like this?

SQL SELECT row FROM table WHERE id=max(id)

1 Answer

0 votes
by (40.7k points)

You can use the subselect like this:

SELECT row 

FROM table 

WHERE id=(

    SELECT max(id) FROM table

    )

Note: If the value of max(id) is not unique, multiple rows will be returned. But, if you only want one such row then use this:

SELECT row from table ORDER BY id DESC LIMIT 1

Related questions

0 votes
1 answer
0 votes
1 answer
asked Jul 12, 2019 in SQL by Tech4ever (20.3k points)
0 votes
1 answer
0 votes
1 answer

Browse Categories

...