0

I am trying to make a select and and get the last inserted row, I am using the SYSTEM_CREATE_DATE column to track the last one.

So I execute the follow query:

SELECT * FROM tcp_message GROUP BY imei ORDER BY create_date DESC;

But I am not getting the last row but the first.

Am I missing something?

Ugo Guazelli
  • 703
  • 3
  • 8
  • 19
  • It's not clear why you are using a GROUP BY here. What are you trying to do with that? – GendoIkari Jan 21 '16 at 18:00
  • 1
    I'm assuming you want the last inserted row for each distinct IMEI ordered by create_date? Your GROUP BY is likely collapsing all of the entries for IMEI and giving you the oldest date, and not the most recent. – mcriecken Jan 21 '16 at 18:01
  • 1
    You're retrieving all the rows so the row that that is returned last is the first inserted row. If you want the last row try using SELECT TOP 1 * FROM tcp_message ... – djebeeb Jan 21 '16 at 18:03

0 Answers0