Home Forums SQL Server 7,2000 T-SQL T-SQL Equivalent to MS Access'' "First" function RE: T-SQL Equivalent to MS Access'' "First" function

  • Stephen is kind of right, as long as you ignore some stuff.

    unless you've added a primary key to the table, because Access is file based, Access really does keep the files in the physical order they were data entered.

    In SQL,As soon as you index the table, or add a PK, the data will be reordered, and will vary from the original natural order. aCCESS JUST KEEPS POINTERS, SO THE FIRST() STILL RETURNS b. I think if you compact a database, the data might be reordered, but i'm not sure.

    SQL Server will do the same thing, a heap table with no PK or indexes is still kept internally in the same order as it was data entered, just awaiting an ORDER BY Clause.

    First() really is the same as the TOP 1 function, regardless.

    As everyone was emphasizing a year ago, an ORDER BY clause is the best practice in order to assure consistant results.

    Saying an order by is not necessary is just assuming that more advanced administration like adding indexes will never occur. on simple databases, that's probably true, but that doesn't mean there is not a better way to do it.

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!