I am using the following queries to find first as well as last inserted records from a table
SELECT TOP (1) titlenumber
FROM cataloguebase
SELECT TOP(1) titlenumber
FROM cataloguebase
ORDER BY titlenumber DESC;
but how can I get first and last record using single query? At list is possible using HQL query?
Use MAX
and MIN
:
SELECT
MAX(titlenumber) AS MaxTitleNumber,
MIN(titlenumber) AS MinTitleNumber
FROM cataloguebase
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