Jump to content

Mysql Max(id)???


tom_b

Recommended Posts

I have a DB set up something like this:

 

id      name      numbers

1          me              10

2          you            15

3          them          20

4          me              25

5          you            30

6          them          35

 

what I need is to get the the last entry for each name.  I've tried all sort of variations of Max(id) as well as different group by, order by etc, no luck, any ideas?

 

Link to comment
https://forums.phpfreaks.com/topic/40441-mysql-maxid/
Share on other sites

How about

 

SELECT id, name, numbers
FROM table
WHERE id IN (
  SELECT max(id) FROM numbers
  GROUP BY name
);

 

HAVING won't work because the condition is based on both the actual id and max id.  HAVING can only deal with aggregated data, not individual row data.

Link to comment
https://forums.phpfreaks.com/topic/40441-mysql-maxid/#findComment-195755
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.