@[TOC] #数据库查询多个不同对象中多条记录中最近时间的那条

/* 选择显示某班级所有学生信息 */
/*连接了四张表 /
select a.
from
(select sid,sname,ssex,uid,uname,rid,rnum,kid,kdate,kstatu from mj_student s,mj_util u,mj_kaoqin k,mj_rom r
WHERE s.sclassid=1 and s.sid=k.studentid and s.sromid=r.rid and r.unitid=u.uid) a
where not exists
(select 1 from
(select sid,sname,ssex,uid,uname,rid,rnum,kid,kdate,kstatu from mj_student s,mj_util u,mj_kaoqin k,mj_rom r
WHERE s.sclassid=1 and s.sid=k.studentid and s.sromid=r.rid and r.unitid=u.uid) b
where b.sname=a.sname and b.kdate>a.kdate)

@[TOC] #数据库查询多个不同对象中多条记录中最近时间的那条
@[TOC] #数据库查询多个不同对象中多条记录中最近时间的那条
简单点就是:
/* 查询a中相同sname属性的最近那条记录,b为table a 的别名*/
select a.* from a
where not exists
(select 1 from a b
where b.sname=a.sname and b.kdate>a.kdate)