LoginSignup
0
0

More than 5 years have passed since last update.

PostgreSQL has many を一行だけ連携する

Posted at

PostgreSQL has many を一行だけ連携する方法

table1 has many table2 の関係で
table2 を最新の1行だけ連携させたい場合のSQL

SELECT *
FROM table1 t1
LEFT JOIN table2 t2 ON t2.id = ( 
    SELECT max(id) FROM table2 t3 
    WHERE t1.id = t3.table1_id
)
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0