我不知道你是哪个意思(是所有记录最大或是每组中最大按clientid分组)
select max(a.id) from 表1 a ,表2 b where a.clientid=b.clientid
或者
select a.clientid,max(a.id) from 表1 a ,表2 b where a.clientid=b.clientid
group by a.clientid
select max(a.id) from 表1 a ,表2 b where a.clientid=b.clientid
或者
select a.clientid,max(a.id) from 表1 a ,表2 b where a.clientid=b.clientid
group by a.clientid
解决方案 »
- 求助:Rollback是否把定义的变量也回滚了?
- 数据库跨库访问之效能问题请教
- 高手指点,如果用SQL语句计算两地坐标之间的距离
- SQLState = 28000, NativeError = 18452
- sql2005远程连接sql2008出现错误
- 各位大哥帮忙!差异备份数据库我如何可以备份到现在到5天以前的数据库??这样可以做到吗?
- 向高手请教一个棘手的问题
- SQL字符串处理
- 方法返回值问题
- 使用ms sql server ,我能在程序中创建一个job,在job中写sql ,对表中的某个字段进行修改吗?
- 求一个单表查询的sql(结果的列要能动态改变,列数不固定......)
- 请问下sql 十进制转十六进制的函数怎么写,谢谢哥哥姐姐。
from 表1 t
where exists(select 1 from 表2 where ClientID=t.ClientID)
and
not exists(select 1 from 表1 where ID>t.ID)
a.ClientID,ID = max(b.ID)
from
表2 a,
表1 b
where
a.ClientID = b.ClientID
group by
a.ClientID
若唯一
select top 1 * from table1,table2 where table1.clientid=table2.clientid
order by table1.id desc若不唯一select * from table1,table2 where table1.clientid=table2.clientid
and table1.id =(select max(id) from table1)
From 表1 A
Where ID = ( Select Max(ID) From 表1 Where ClientID = A.ClientIDF)