The Top function would work if you want to grab the highest numbered
identity field in your table (you could also use the SQL function
getMax(ColumnName)), but I think you are probably trying to grab the
auto-incrementing ID of a recently inserted record? If so, you'll probably
want to use another select statement on the same page with @@Identity to
grab the exact ID you just inserted...
<cfquery query="getSelectedID" datasource="MyDataSource">
SELECT @@Identity AS MyNewID
FROM MyTable
</cfquery>
If this isn't what you're trying to do, oh well, but if it is; I'm
relatively positive that this will ensure you get the ID of your previous
query and not risk the chance a grabbing someone else's ID of a simultaneous
insert...
CF/SQL experts: please let me know if I'm wrong here->
Tyler
email | [EMAIL PROTECTED]
----- Original Message -----
From: "Steve Oliver" <[EMAIL PROTECTED]>
To: "CF-Talk" <[EMAIL PROTECTED]>
Sent: Monday, January 21, 2002 7:09 AM
Subject: RE: Retrieving most recent record from db
I believe the first example would be less of a load on the DB and CF.
The first example tells the database using SQL to only return the top 1
row.
The second example tells the database to SELECT ALL rows, then CF only
outputs 1.
Both will return the same results though.
______________________
steve oliver
cresco technologies, inc.
http://www.crescotech.com
-----Original Message-----
From: Teng-Yan Loke [mailto:[EMAIL PROTECTED]]
Sent: Sunday, January 20, 2002 9:42 PM
To: CF-Talk
Subject: RE: Retrieving most recent record from db
> <CFQuery = "q_results>
> SELECT Top 1 * FROM T_EMAIL
> ORDER BY Eid DESC
> </CFQUERY>
Assuming this has the same output as:
<cfquery query="q_results" maxrows="1">
select * from t_email
order by eid desc
</cfquery>
Will the former example yield less load from the DB server than the
latter?
----
Teng-Yan Loke | [EMAIL PROTECTED]
Developer | novaSPRINT Systems Pte Ltd
tel: +65-2169727 | fax: +65-3390279
______________________________________________________________________
Get Your Own Dedicated Windows 2000 Server
PIII 800 / 256 MB RAM / 40 GB HD / 20 GB MO/XFER
Instant Activation � $99/Month � Free Setup
http://www.pennyhost.com/redirect.cfm?adcode=coldfusionb
FAQ: http://www.thenetprofits.co.uk/coldfusion/faq
Archives: http://www.mail-archive.com/[email protected]/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists