Re: Running counter

From: Hugo Kornelis (hugo_at_pe_NO_rFact.in_SPAM_fo)
Date: 12/28/04


Date: Tue, 28 Dec 2004 10:05:40 +0100

On Mon, 27 Dec 2004 16:08:54 -0800, MichaelK wrote:

>Thanks Hugo.
>Interesting idea and works, but takes very long.
>Unfortunately can't use it, need something faster.
>
>Hey guys any other ideas?

Hi Michael,

Here's another way to write the same query, that might perform quicker
(you'll need to test it on your end to see if it's better for you):

SELECT a.au_id, a.au_lname, a.au_fname,
           1 + COUNT(*) AS rank
FROM authors AS a
INNER JOIN authors AS b
      ON b.au_lname < a.au_lname
GROUP BY a.au_id, a.au_lname, a.au_fname
ORDER BY rank

Another important thing to consider is that the column you use to base the
ranking on should be indexed. A nonclustered index on only that column
would be best for this query. (Of course, the final choice of indexes
should be based on ALL queries, plus the impact of more indexes on insert,
update and delete performance).

Derrick's suggestion might be useful as well. Probably faster than any
truly relational approach. But you should be aware that multi-row inserts
can be handled in any order - even if you write INSERT INTO ... SELECT ...
ORDER BY ..., SQL Server is still free to choose another ordering when
inserting the rows.
Usually, the rows WILL be inserted (and given identity values) in the
order you specify, but this behaviour is NOT guaranteed.

You'll find more useful ideas on this subject in Aaron's article, which is
here: http://www.aspfaq.com/show.asp?id=2427. Be sure to also follow the
links near the end of this article.

Best, Hugo

-- 
(Remove _NO_ and _SPAM_ to get my e-mail address)


Relevant Pages

  • Re: Auto-generate recently visited record-list
    ... mock up a query using your specific table and some ... Form Company with CompanyID as primary key and autonummered / ... Table History with LogID and FkID ... On the company form I added a combo list CompanyName ORDER BY Inserting ...
    (comp.databases.ms-access)
  • Re: Auto-generate recently visited record-list
    ... On the company form I added a combo list CompanyName ORDER BY Inserting ... I made a history table as you wrote to me with LogID and FKID. ... query statement, or AddNew. ... to navigate throught the records ...
    (comp.databases.ms-access)
  • Re: Word 2002 - problem wih linked items in INCLUDETEXT
    ... need whether to continue using this method of inserting chapters or I should ... > Hi Michael, ... >> bookmark appears on. ... > Did you try updating it a couple of times, ...
    (microsoft.public.word.formatting.longdocs)
  • Re: List Box Display Anomaly
    ... Michael, since it works fine on one machine but not on the other, you are looking to pin down the difference. ... There were some bugs introduced by SP3 for Office 2003, including combo display problems: ... All of a sudden, the columns from one of the tables is not displaying in the list box, but if I run the query in the query window, all the columns return data. ... I delivered a new front-end to a client this morning and he alerted me the anomaly. ...
    (microsoft.public.access.forms)
  • Re: Field Validation Rule fails in VBA !
    ... It may occurs that the failure is about inserting a particular ... OPTIONAL FLAG to tell to report the error to VBA: ... whole transaction is compromised, and explicitly roll it back, as example. ... > If I run the exact same query from query designer, ...
    (microsoft.public.access.externaldata)