473,385 Members | 1,536 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,385 software developers and data experts.

Row number in SELECT

Hi,

I currently have a fairly complex query that returns a variable number of
rows, sorted by various criteria. I am trying to insert the result of this
query into an additional table, along with a row number. Ideally, I would
like to be able to do this with an INSERT SELECT statement, although I'm not
sure quite how to achieve this. An example of what I'm trying to achieve
might be:

INSERT INTO tblfinishingpositions (raceid, personid, position)
SELECT raceid, personid, XXXXXXXXX
FROM tblfinishingtimes WHERE raceid = XYZ

At present, I'm just reading the rows one at a time, and issueing multiple
insert statements, but I would rather have something all server side if
possible. I have considered usign a temporary HEAP table, with an
autonumber field, but this seems like a bit of a kludge, and I would prefer
a single statement to do the whole lot.
Another problem that I have now overcome by use of a tempory table, but
would prefer to tidy is the following:

Say one had a table of cars: Manufacturer, Model, Price

How would one answer the question, what is the model of the cheapesest car
for each manufacturer. Obtaining the price is obviously very
straightforward:

SELECT MIN(price) FROM cars GROUP BY manufacturer

However, I couldn't find an easy way to find the corresponding model. In
the end, I had to insert the results into a temporary table, and join back
on manufacturer, and price (or their equivalents, which can be assumed to be
unique)
Any advice on either of the above problem would be much appreciated,

Chris Key
Jul 20 '05 #1
0 1368

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

Similar topics

1
by: Bryan Zash | last post by:
When querying a bit field, I am encountering a problem with MS SQL Server returning a larger number of records for a table than the actual number of records that exist within that table. For...
0
by: johkar | last post by:
My XML and XSL is below. Also below is a textual representation of what I want to get out of the XML with XSL. For each Extension node in XML, I am only concerned with those nodes with...
0
by: D. Dante Lorenso | last post by:
I need to know that original number of rows that WOULD have been returned by a SELECT statement if the LIMIT / OFFSET where not present in the statement. Is there a way to get this data from PG ?...
7
by: Shuffs | last post by:
Could someone, anyone please tell me what I need to amend, to get this function to take Sunday as the first day of the week? I amended the Weekday parts to vbSunday (in my code, not the code...
1
by: sunilkeswani | last post by:
Hi I am still new to access. I want to know how i can build a query which can display results from 4 different columns/fields Like. Field1 Field2 Field3 Field4 1 2 1 ...
4
by: dba_222 | last post by:
Dear Experts, Ok, I hate to ask such a seemingly dumb question, but I've already spent far too much time on this. More that I would care to admit. In Sql server, how do I simply change a...
15
by: Hexman | last post by:
Hello All, How do I limit the number of detail records selected in a Master-Detail set using SQL? I want to select all master records for a date, but only the first 3 records for the details...
0
by: sysmanint1 | last post by:
I am a total neophyte at Visual Basic but found the following post and reply from Clint concerning a dynamic range. Also, have never "posted" to a discussion I have made a macro that works on...
1
by: zafm86 | last post by:
Hi everyone! I'm sure my problem is pretty easy to solve but I've been working on it for a long and my my brain is not working correctly anymore. I'm working with an AS400 and I mhave to do an...
5
by: Jonathan Wood | last post by:
Greetings, I'm using ASP.NET membership and I'd like to query the number of users in a particular role. I don't want the overhead of returning a dataset and then getting the number of items...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...

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.