F
F
FlorenceMachine2020-12-07 17:10:41
SQL
FlorenceMachine, 2020-12-07 17:10:41

How to get the latest from records with the same id?

I'm using PhpMyAdmin, when I run a query

SELECT books.name, 
       books.pub_date, 
       books.id, 
       log_taking.returned_at, 
       log_taking.taken_at, 
       readers.last_name, 
       readers.first_name 
  FROM books
       JOIN log_taking ON books.id = log_taking.book_id
       JOIN readers ON readers.id = log_taking.reader_id


i get a table
5fce372500eb3831887250.png

books, log_taking and readers are database tables.
I want to get the latest entry of each id. That is, output only the lines underlined in red.

How to rewrite a query?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
ThunderCat, 2020-12-07
@ThunderCat

group by + order by

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question