Re: why the result of the query is in asending order



Hi, Hugo

thanks for ur kind reply
what u suggest me, will not solve my problem

i want to do exactly reverse of this

I dont want my data(result of query)to be order by.

i want to know why sql server returns me data in order by

Pravin


"Hugo Kornelis" wrote:

> On Mon, 18 Apr 2005 04:21:02 -0700, bhavik wrote:
>
> (snip)
> >i want my result to be
> >
> >in the following way(which is the actual order in routesegment : desirable)
> >
> >
> >locationname locationid
> >---------------------------------------
> >Gallery 20
> >loc2 25
> >loc1 24
> >WP2 27
> >WP1 26
> >wp3 28
> >
> >
> >why the result of the query is in asending order
>
> Hi Pravin,
>
> Since you didn't specify an ORDER BY clause in your query, SQL Server is
> free to return the rows in any order it sees fit. The optimizer will
> create an execution plan that will minimize the execution time, without
> regard for the order in which rows are returned. Explaining why this
> particular order is used requires full knowledge of your tables, all
> indexes, statistics about numbers of rows and data distribution, details
> of your server, other processes running at the same time and a fair
> amount of guessswork.
>
> >
> >is ther any solution
>
> The only way to make sure you get the rows in the order you need them is
> to specify an ORDER BY clause. I'm not sure if I understand your data
> correctly, but I *think* that this one will return the rows in the order
> you want them:
>
> SELECT
> distinct locationname,locationid
> FROM
> routesegment
> ,location
>
> WHERE
> (startlocation=locationid
> or
> endlocation=locationid)
> and
> routeid=@routeid
> ORDER BY rsid -- <-- Add this line
>
> Best, Hugo
> --
>
> (Remove _NO_ and _SPAM_ to get my e-mail address)
>
.



Relevant Pages

  • Re: Query
    ... passing a where clause to a stored procedure is a token of a weak ... Remember that SQL Server will call them for each row in the ... optimization options). ... * Check the execution plan. ...
    (microsoft.public.sqlserver.programming)
  • Index chosen is wrong index
    ... I'm on SQL Server 2000 SP3. ... The execution plan for the query below selects the wrong ... which is not even in the where clause nor the ...
    (microsoft.public.sqlserver.server)
  • Re: Query
    ... "Hugo Kornelis" wrote: ... passing a where clause to a stored procedure is a token of a weak ... Remember that SQL Server will call them for each row in the ... > * Check the execution plan. ...
    (microsoft.public.sqlserver.programming)
  • Re: Query is very slow after server reboot
    ... > if u r using this column in Where Clause or some other equations it ll ... >> The execution time of the stored procedure increased five times after ... >> After looking into statics and execution plan I found that it happens ... >> I am still baffled why would reboot cause such huge performance ...
    (microsoft.public.sqlserver.server)
  • Re: very strange stored procedure behavior
    ... > im having trouble with a stored procedure. ... > and keeps that execution plan im memory, so my idea was that this ... > helped to lower execution time to about 60ms, ... > sql server to get rid of a stored procedure COMPLETELY so that i can ...
    (microsoft.public.sqlserver.programming)