SQL records the largest date of an attribute

0

I have a table named kanban_card_journals which has the following attributes:

  • id
  • kanban_card_id
  • issue_journal_id
  • created_at

Where the first three are numbers and the last date and time. This table saves the date of all changes by kanban card . My problem is that I need to know the last time a kanban card was updated, that is, the last update date of a kanban_card_id .

I tried the command:

select distinct id, kanban_card_id, created_at from kanban_card_journals where kanban_card_journals.created_at = (select max(created_at) from kanban_card_journals);

It returns me the data from the last updated record, but I do not know how it does to bring the last of each card.

    
asked by anonymous 19.02.2016 / 14:10

1 answer

0

You are looking for the largest general date, without considering every kanban_card_id.  

SELECT distinct id, kanban_card_id, created_at FROM kanban_card_journals GROUP BY kanban_card_id HAVING MAX(created_at);

In this query I added the GROUP BY clause and a HAVING clause at the end. This way SELECT will bring the records with the largest dates grouping by kanban_card_id .

    
19.02.2016 / 14:17