Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在sql中查找最大值和关联字段?_Sql - Fatal编程技术网

如何在sql中查找最大值和关联字段?

如何在sql中查找最大值和关联字段?,sql,Sql,我试图使用以下代码从表中选择最高ID及其描述。但是它总是返回null。有人能告诉我哪里出了问题吗 Select ID, Description FROM STOPS where Description = (select MAX(ID) from STOPS); 使用order by和等效的仅获取前1行: select s.* from stops s order by s.id desc fetch first 1 row only; 这是ANSI标准语法。并非所有数据库都支持fetc

我试图使用以下代码从表中选择最高ID及其描述。但是它总是返回null。有人能告诉我哪里出了问题吗

Select  ID, Description
FROM STOPS
where Description = (select MAX(ID) 
from STOPS);

使用
order by
和等效的
仅获取前1行

select s.*
from stops s
order by s.id desc
fetch first 1 row only;

这是ANSI标准语法。并非所有数据库都支持
fetch first
,有些数据库使用
limit
select top
,或
rownum
,使用
order by
和等效的
仅获取第一行

select s.*
from stops s
order by s.id desc
fetch first 1 row only;

这是ANSI标准语法。并非所有数据库都支持
fetch first
,有些数据库使用
limit
select top
,或者
rownum
使用您正在使用的数据库标记您的问题。
其中ID=(选择MAX(ID).
使用您正在使用的数据库标记您的问题。
其中ID=(选择MAX(ID).