Jump to content

Table with same row name


Recommended Posts

So given this table as a example


Name, ID, RandomStuff

Jon, 1, Blah

Jon, 2, MoreBlah

Tim, 4, EvenMoreBlah

Bob, 12, HiThere


Given that the table has rows with the same name but different IDs, how do you select the highest ID of the rows with the same name while still grabbing the rest of the table for display?

Link to comment
Share on other sites

This should work:

SELECT Name, MAX(ID), RandomStuff FROM table GROUP BY Name

With this code, you will not be able to know exactly which of the duplicated rows the rest of the data comes from. If you actually want to specify which row you want you're going to need a more complicated query.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...