A
A
Anton2018-11-12 19:36:59
SQLite
Anton, 2018-11-12 19:36:59

How to organize a selection by date in SQLite?

Please tell me how to organize a selection from the table by two dates.
For example, there is a table "persons" (see attachment) Please tell me
how to select values ​​from the fields "name", "date1" from the table, but at the same time include records in the response only with the maximum date of the "date2" field.
5be9a8c43998f481197182.png
That is, the response should look like this:
5be9a8f1cc6df861068432.png
Example DB:
test_BDtest.db - Download file

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
Konstantin Tsvetkov, 2018-11-12
@8toni8

Compose a subquery grouped by name and maximum date. Then to connect with the main table on the fields "name" and "date2".

N
nozzy, 2018-11-12
@nozzy

select
t1.name,
t1.date1,
t2.date2
from persons t1
join (
  select
  name,
  max(date2) as date2
  from persons
  group by name
) t2 on t2.name = t1.name and t2.date2 = t1.date2

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question