Home  >  Q&A  >  body text

Get latest data from SQL based on date or ID

How to get the latest data from this query, actually the table is crowded and we need the latest data for the past 2 years, how can I modify my query accordingly.

Select stagingScriptDB.*, testBedSuiteMapping.template from stagingScriptDB inner join testBedSuiteMapping on testBedSuiteMapping.id = stagingScriptDB.idScriptDB limit 10;

P粉153503989P粉153503989399 days ago597

reply all(1)I'll reply

  • P粉464113078

    P粉4641130782023-09-16 21:16:52

    It would be great if you share the table structure.

    We can use this query type to retrieve the last record of id

    SELECT * FROM table_name
    WHERE ID IN (
      SELECT max(ID) FROM table_name
      GROUP BY column_name
      ORDER BY column_name
    )
    

    reply
    0
  • Cancelreply