Skip to main content
Outer query can't order by a column not offered by the inner query.
Source Link
Aaron Bertrand
  • 282.4k
  • 37
  • 471
  • 469

This solution only works while you have > 1 rows in your table.

SELECT TOP 1 meetings_id FROM
(SELECT TOP 2 meetings_id, meetings_date FROM meetings 
 ORDER BY meetings_date DESC) x                     
ORDER BY meetings_date;

Based on answer from this link.

You'll probably get an error or empty result since there is no penultimate row. So your query will be faulty in this case.

This solution only works while you have > 1 rows in your table.

SELECT TOP 1 meetings_id FROM
(SELECT TOP 2 meetings_id FROM meetings ORDER BY meetings_date DESC) x                     
ORDER BY meetings_date;

Based on answer from this link.

You'll probably get an error or empty result since there is no penultimate row. So your query will be faulty in this case.

This solution only works while you have > 1 rows in your table.

SELECT TOP 1 meetings_id FROM
(SELECT TOP 2 meetings_id, meetings_date FROM meetings 
 ORDER BY meetings_date DESC) x                     
ORDER BY meetings_date;

Based on answer from this link.

You'll probably get an error or empty result since there is no penultimate row. So your query will be faulty in this case.

added 199 characters in body; deleted 27 characters in body
Source Link
L0ndl3m
  • 139
  • 5

YourThis solution is:only works while you have > 1 rows in your table.

SELECT TOP 1 meetings_id FROM
(SELECT TOP 2 meetings_id FROM meetings ORDER BY meetings_date DESC) x                     
ORDER BY meetings_date;

Based on answer from this link.

You'll probably get an error or empty result since there is no penultimate row. So your query will be faulty in this case.

Your solution is:

SELECT TOP 1 meetings_id FROM
(SELECT TOP 2 meetings_id FROM meetings ORDER BY meetings_date DESC) x                     
ORDER BY meetings_date;

Based on answer from this link.

This solution only works while you have > 1 rows in your table.

SELECT TOP 1 meetings_id FROM
(SELECT TOP 2 meetings_id FROM meetings ORDER BY meetings_date DESC) x                     
ORDER BY meetings_date;

Based on answer from this link.

You'll probably get an error or empty result since there is no penultimate row. So your query will be faulty in this case.

Source Link
L0ndl3m
  • 139
  • 5

Your solution is:

SELECT TOP 1 meetings_id FROM
(SELECT TOP 2 meetings_id FROM meetings ORDER BY meetings_date DESC) x                     
ORDER BY meetings_date;

Based on answer from this link.