Select if it does not exist in another table, but if there is no record in 24h

0

I have two tables:

links

works I need to return values from the links table, but first I need to see if it exists in the works table, and if it exists it must have been inserted more than 24h, otherwise this record can not be returned in the query. >

Querying and returning only what I do not have in the works table is easy, I do so:

SELECT *
FROM links l
WHERE NOT EXISTS 
(
    SELECT * 
    FROM works w
    WHERE w.linkId = l.linkId
) 

But I need to return only records entered more than 24h

    
asked by anonymous 14.02.2018 / 15:26

1 answer

0

You can add the checking of datahora to your sub-select using the DATE_SUB function:

SELECT *
FROM links l
WHERE NOT EXISTS 
(
    SELECT * 
    FROM works w
    WHERE w.linkId = l.linkId
    AND w.datahora <= DATE_SUB(NOW(), INTERVAL 24 HOUR);
) 

See more about DATE_SUB here .

    
14.02.2018 / 17:25