corsasport.co.uk
 

Corsa Sport » Message Board » Off Day » Geek Day » sql statement


New Topic

New Poll
  Subscribe | Add to Favourites

You are not logged in and may not post or reply to messages. Please log in or create a new account or mail us about fixing an existing one - register@corsasport.co.uk

There are also many more features available when you are logged in such as private messages, buddy list, location services, post search and more.


Author sql statement
Jodi_the_g
Member

Registered: 7th Aug 01
Location: Washington D.C
User status: Offline
15th Feb 08 at 15:24   View User's Profile U2U Member Reply With Quote

sql = "SELECT MAX(trackid) FROM track"

I want to select the highest record how do I do this.
Nismo
Member

Registered: 12th Sep 02
User status: Offline
15th Feb 08 at 15:35   View User's Profile U2U Member Reply With Quote

ORDER BY trackid ASC / DESC
Jodi_the_g
Member

Registered: 7th Aug 01
Location: Washington D.C
User status: Offline
15th Feb 08 at 15:37   View User's Profile U2U Member Reply With Quote

Yeah but i just want the last record as i need the valve for another table.
James
Member

Registered: 1st Jun 02
Location: Surrey
User status: Offline
15th Feb 08 at 15:39   View User's Profile U2U Member Reply With Quote

What you have should work

or

SELECT TOP 1 TrackId FROM Track ORDER BY TrackId DESC
James
Member

Registered: 1st Jun 02
Location: Surrey
User status: Offline
15th Feb 08 at 15:40   View User's Profile U2U Member Reply With Quote

If you want the whole row do it like this:

SELECT * FROM Track WHERE TrackId = (SELECT MAX(TrackId) FROM Track)

[Edited on 15-02-2008 by James]
Ian
Site Administrator

Avatar

Registered: 28th Aug 99
Location: Liverpool
User status: Online
15th Feb 08 at 17:56   View Garage View User's Profile U2U Member Reply With Quote

Full record in MySQL

SELECT * FROM track ORDER BY trackid DESC LIMIT 1

Your example in the first post will give you highest track id in the table though - is that not what you want?
Jodi_the_g
Member

Registered: 7th Aug 01
Location: Washington D.C
User status: Offline
15th Feb 08 at 19:24   View User's Profile U2U Member Reply With Quote

I thought that Ian but for some reason it throws an error stupid real basic, I hate developing mac applications.
Ian
Site Administrator

Avatar

Registered: 28th Aug 99
Location: Liverpool
User status: Online
15th Feb 08 at 19:27   View Garage View User's Profile U2U Member Reply With Quote

SQL error will be the fact that I've given you MySQL syntax and not generic SQL.

You need either an aggregate function to work out the max or an order by and take one record. Just read the docs for either of those approaches.

 
New Topic

New Poll

  Related Threads Author Forum Replies Views Last Post
Important - AOL users or anyone requiring renaming Ian General Chat 22 571
19th Sep 03 at 19:48
by Drew
 
Doing my head in help! Steve Geek Day 5 139
19th Jul 06 at 16:02
by robmarriott
 
FAO: Programmers barteh Geek Day 6 779
6th Nov 07 at 14:02
by barteh
 
SQL server Dan Lewis Geek Day 1 295
30th Jan 08 at 17:15
by Dan Lewis
 
System Center Configuration Manager 2007 Pablo Geek Day 13 353
6th Feb 08 at 14:39
by Pablo
 

Corsa Sport » Message Board » Off Day » Geek Day » sql statement 29 database queries in 0.1352351 seconds