Join to only the “latest” record with t-sql

前端 未结 7 893
你的背包
你的背包 2020-12-08 08:28

I\'ve got two tables. Table \"B\" has a one to many relationship with Table \"A\", which means that there will be many records in table \"B\" for one record in table \"A\".<

7条回答
  •  旧巷少年郎
    2020-12-08 08:45

    This will fetch the latest record with JOIN. I think this will help someone

    SELECT cmp.*, lr_entry.lr_no FROM 
    (SELECT * FROM lr_entry ORDER BY id DESC LIMIT 1) 
    lr_entry JOIN companies as cmp ON cmp.id = lr_entry.company_id
    

提交回复
热议问题