473,396 Members | 1,765 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

How to do an equivelent First() operation

rss
set rowcount 1
select Idnum1,Idnum3 from mytable order by Idnum1 DESC, idnum3 ASC

is equivelent to
select first(Idnum1),first(idnum3) from mytable order by first(Idnum1)
DESC ,first(Idnum3) ASC
Isn't that silly? why did Microsoft not add an agregate function First
for the Microsoft SQL Server to be consistent with its Microsoft Access
product eh?

May 3 '06 #1
3 1524
As you are learning, SQL Server has little in common with Access. SQL
Server stays much closer to the relational model. In this case, the
relational model tells us that tables are un-ordered sets; there is no
concept of first or last in sets.

The SQL Server 2005 documentation also says that set rowcount will be
going away some day. We should be using TOP instead, in this case TOP
1. With an ORDER BY, TOP 1 will return the "first" row as determined
by the ORDER BY. Without the ORDER BY the single row returned is
random.

Roy Harvey
Beacon Falls, CT

On 3 May 2006 12:45:58 -0700, rs*@ddsc.com wrote:
set rowcount 1
select Idnum1,Idnum3 from mytable order by Idnum1 DESC, idnum3 ASC

is equivelent to
select first(Idnum1),first(idnum3) from mytable order by first(Idnum1)
DESC ,first(Idnum3) ASC
Isn't that silly? why did Microsoft not add an agregate function First
for the Microsoft SQL Server to be consistent with its Microsoft Access
product eh?

May 3 '06 #2
rs*@ddsc.com wrote:
set rowcount 1
select Idnum1,Idnum3 from mytable order by Idnum1 DESC, idnum3 ASC

is equivelent to
select first(Idnum1),first(idnum3) from mytable order by first(Idnum1)
DESC ,first(Idnum3) ASC
Isn't that silly? why did Microsoft not add an agregate function First
for the Microsoft SQL Server to be consistent with its Microsoft Access
product eh?


RANK() and ROW_NUMBER() are much more powerful alternatives. FIRST is
not a proper aggregate function, even in Access. RANK() and
ROW_NUMBER() are also ANSI-standard SQL functions. One would hope that
ANSI compatibility is a higher priority for inclusion than replicating
the peculiar quirks of Access.

--
David Portas, SQL Server MVP

Whenever possible please post enough code to reproduce your problem.
Including CREATE TABLE and INSERT statements usually helps.
State what version of SQL Server you are using and specify the content
of any error messages.

SQL Server Books Online:
http://msdn2.microsoft.com/library/m...S,SQL.90).aspx
--

May 3 '06 #3

"Roy Harvey" <ro********@snet.net> wrote in message
news:bj********************************@4ax.com...
As you are learning, SQL Server has little in common with Access. SQL
Server stays much closer to the relational model. In this case, the
relational model tells us that tables are un-ordered sets; there is no
concept of first or last in sets.

The SQL Server 2005 documentation also says that set rowcount will be
going away some day. We should be using TOP instead, in this case TOP
1. With an ORDER BY, TOP 1 will return the "first" row as determined
by the ORDER BY. Without the ORDER BY the single row returned is
random.
Actually row_number() or rank() is an even better solution.

But agreed, rowcount isn't a good solution here.


Roy Harvey
Beacon Falls, CT

On 3 May 2006 12:45:58 -0700, rs*@ddsc.com wrote:
set rowcount 1
select Idnum1,Idnum3 from mytable order by Idnum1 DESC, idnum3 ASC

is equivelent to
select first(Idnum1),first(idnum3) from mytable order by first(Idnum1)
DESC ,first(Idnum3) ASC
Isn't that silly? why did Microsoft not add an agregate function First
for the Microsoft SQL Server to be consistent with its Microsoft Access
product eh?

May 4 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: John Baker | last post by:
Hi: I have a Pop Up form that involves a main form and sub form. The sub form has the results of a query on the main form. I need to automatically perform exactly he same action that takes...
7
by: Poewood | last post by:
I store all my global functions in modules when using vb. What is the equivelent convention in C#. I am converting a .net compact frmwk project from vb to C#. Thanx, Poe
8
by: bryan | last post by:
Is there any way I can get the application path (the one returned by Request.ApplicationPath) in the Application_Start method in Global.asax? Request is not valid there. On a related note, is there...
10
by: Kevin R | last post by:
This week I've begun to learn vb.net by re-writing an existing VB app. I'm having a difficult time figuring how to add new records to an ADODB recordset. How would I re-write the '.AddNew'...
10
by: Dave Cox | last post by:
of "int" in VB? //b=1.2 b=int(b) //b now equals 1
7
by: lathamik | last post by:
Does anyone know of the vb.net equivelent to the c# continue so I can exit the immediate iteration of a for loop and continue with the next one.
23
by: pirata | last post by:
I'm a bit confusing about whether "is not" equivelent to "!=" if a != b: ... if a is not b: ... What's the difference between "is not" and "!=" or they are the same thing?
21
by: Mike N. | last post by:
Can someone tell me if there is a C# equivelent to the VBA 'with' statement that works like this: Set myControl = CommandBars(PopUpToUse).Controls.Add(msoControlButton, before:=5) With...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.