PostgreSQL , Select from 2 tables, but only the latest element from table 2

后端 未结 5 2068
星月不相逢
星月不相逢 2021-02-07 07:07

Hey, I have 2 tables in PostgreSql:

1 - documents: id, title
2 - updates: id, document_id, date

and some data:

documents:

5条回答
  •  野趣味
    野趣味 (楼主)
    2021-02-07 07:35

    This should also work

    SELECT * FROM documents, updates 
        WHERE documents.id=1 AND updates.document_id=1
        AND updates.date = (SELECT MAX (date) From updates) 
    

提交回复
热议问题