During my studies, I tried to sort the records and put the ones that are NULL
at the end, I did the following:
SELECT
tbl1.firstname,
tbl1.mgrid
FROM
(
SELECT TOP 100 firstname, mgrid
FROM HR.Employees
WHERE mgrid IS NOT NULL
ORDER BY mgrid
) tbl1
UNION ALL
SELECT
tbl2.firstname,
tbl2.mgrid
FROM
(
SELECT TOP 100 firstname, mgrid
FROM HR.Employees
WHERE mgrid IS NULL
ORDER BY mgrid
) tbl2
I was not interested in putting TOP
, but I discovered that when using a query within FROM
, it is mandatory to set TOP
(at least in the version I use), TOP
a quantity parameter, but I do not have a fixed quantity, so I would like to know if there is something like SELECT TOP all
.
Thank you!