开发者

check if master record date in table A is later than latest records date in joined table B

开发者 https://www.devze.com 2023-04-12 12:26 出处:网络
I have a master table people people fields: Id,AlterationDate And开发者_开发技巧 an actions table actions in a one to many linkage

I have a master table people

people fields: Id,AlterationDate

And开发者_开发技巧 an actions table actions in a one to many linkage

actions fields: Id, PeopleID, CreationDate

I want to find all records in people whose alteration dates are later than the latest creation date in actions joined by the persons id.

MySQL is the dialect, Dates are DateTime fields.


select people.* from people  
join actions on actions.peopleID = people.id  
group by people.id  
having max(action.CreationDate) < people.AlterationDate


try

select p.peopleid 
from actions a 
inner join people p on p.peopleid = a.peopleid 
group by p.peopleid 
having max (a.creationdate) < p.alterationdate
0

精彩评论

暂无评论...
验证码 换一张
取 消