Answer the question
In order to leave comments, you need to log in
DB query with join?
There are two
urls tables: id, name, created_at, updated_at;
and
urls_checks: id, url_id, status, created_at, updated_at;
I make a request
SELECT * FROM urls JOIN url_checks ON urls.id = url_checks.url_id
HAVING/WHERE max(url_checks.updated_at)
Answer the question
In order to leave comments, you need to log in
We use window functions:
SELECT
*
FROM (
SELECT
url_id,
status,
updated_at,
ROW_NUMBER() OVER (PARTITION BY url_id ORDER BY updated_at DESC) rn
FROM urls_checks
ORDER BY urls_checks DESC
) checks
JOIN urls on urls.id = checks.url_id
WHERE rn = 1;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question