[thelist] Quick SQL question

Jason Handby jasonh at pavilion.co.uk
Mon Feb 10 15:50:01 CST 2003


.jeff wrote:
> SELECT *
>   FROM MyTable
>  WHERE Col_ID IN (SELECT TOP 15 Col_ID
>                     FROM MyTable
>                    ORDER BY Col_ID DESC)
>  ORDER BY Col_ID ASC
>
> kinda icky though.

I quite like it...

In MS-SQL Server you could also do

	SELECT * FROM
		(SELECT TOP 15 * FROM MyTable ORDER BY Col_ID DESC) MyTable
	ORDER BY Col_ID ASC

which gets me an an arguably nicer execution plan than your version,
although they both seem to run at about the same speed.



Jason




More information about the thelist mailing list