I am using sybase database to query the daily transaction report. I had subquery within my script.
Here as it goes:
SELECT orders.accountid ,items.x,etc
(SELECT charges.mistotal FROM charges where items.id = charges.id)
FROM items,orders
WHERE date = '2008-10-02'
Here I am getting the error message as:
Subquery cannot return more than one values
My values are 7.50, 25.00
I want to return the 25.00, but when I use
(SELECT TOP 1 charges.mistotal FROM charges where items.id = charges.id)
My result is 7.50 but I want to return 25.00
Does anyone has any better suggestion?
We can use the ORDER BY statement and LIMT clause to extract the last data. The basic idea is to sort the sort the table in descending order and then we will limit the number of rows to 1. In this way, we will get the output as the last row of the table. And then we can select the entry which we want to retrieve.
No, there is no BOTTOM operator.
The LAST() function returns the last value of the selected column.
SQL LAST() function returns the last value of the given column. SQL LEN() function returns the total length of the given column.
SELECT TOP 1 *
FROM dbo.YourTable
ORDER BY Col DESC
In your case, I guess that would be
SELECT TOP 1 charges.mistotal
FROM charges where items.id = charges.id
ORDER BY charges.mistotal DESC
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With