2012年2月24日星期五

First & last record retrieve

Is there a simple SQL statement to get the
last and first record of a table under
Access and SQL Server ?
Thanks,
Pierre.Tables have no concept of "first" and "last". You need to create a column by which you can order the data. Then you can do something like:

SELECT * FROM t WHERE col IN (SELECT MIN(col) FROM t
UNION SELECT MAX(col) FROM t);

没有评论:

发表评论