Hi
I have below code . In inner statement there are multiple reords. I want to get value of 1 record . How it can be done i don't use Max Keyword.
Thanks
SELECT
T2."CardCode",
(
SELECT MAX(I0."Rate")
FROM DPO5 I0
WHERE I0."AbsEntry" = (
SELECT I1."BaseAbs"
FROM PCH9 I1
WHERE I1."DocEntry" = T2."DocEntry"
)
) AS MaxRate
FROM
OPCH T2;
frankleePosted Jan 15, 2025, 6:46 PM
You can use a
TOP 1clause to get a single record without usingMAX.SELECT ColumnName FROM ( SELECT TOP 1 ColumnName FROM TableName WHERE Condition ORDER BY ColumnToOrder ) AS InnerQuery;I’ve come across sites like SCMAPK.com that share similar tech tips—worth checking out. Let me know if you need more help!
Tuhin PaulPosted Jan 15, 2025, 6:34 PM
We can also use the Row_Number() function here:
In the ROW_NUMBER() approach, we use a Common Table Expression (CTE) to rank the rates for each CardCode. Then, we select the top-ranked rate for each CardCode.
NakhatraPosted Jan 15, 2025, 3:55 PM
jignesh is currect .But insted the fild he select from I0 . select top 1 I0.* which missmatch the outer query select field.
select top 1 I0.* from DPO5 I0
Nidhi KumariPosted Jan 15, 2025, 10:12 AM
Try this
Jignesh KumarPosted Jan 15, 2025, 9:41 AM
Hello Ramco,
You can do as below, Limit 1 or you can use Top 1