Jodi_the_g
Member
Registered: 7th Aug 01
Location: Washington D.C
User status: Offline
|
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
|
ORDER BY trackid ASC / DESC
|
Jodi_the_g
Member
Registered: 7th Aug 01
Location: Washington D.C
User status: Offline
|
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
|
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
|
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
Registered: 28th Aug 99
Location: Liverpool
User status: Offline
|
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
|
I thought that Ian but for some reason it throws an error stupid real basic, I hate developing mac applications.
|
Ian
Site Administrator
Registered: 28th Aug 99
Location: Liverpool
User status: Offline
|
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.
|