i want to make a select on :
id num
------- ----------
28431 222.3347
28451 222.3346
28452 502.2256
where i want to get the max(id) but it's "num" too !!!
i tried :
select max(id),num from xxx group by id
and it gave me all the rows and not just the max(id)
what can i do?
thnaks in advane
peleg
selecting max value
Moderator: General Moderators
Are you using MySQL as your database? I don't know much about SQL statements but I hope this helps.
Basically it's selecting the 2 fields you want, ORDER BY id DESC so you get the highest id on top, and then LIMIT 1 makes it so it returns only 1 row.
I assume id is of integer type. If it's of string, I'm not sure if ORDER BY id DESC would work the way I expected it to be.
LIMIT works only in MySQL if I'm not wrong.
Code: Select all
SELECT id, num FROM tbl ORDER BY id DESC LIMIT 1I assume id is of integer type. If it's of string, I'm not sure if ORDER BY id DESC would work the way I expected it to be.
LIMIT works only in MySQL if I'm not wrong.
- pelegk2
- Forum Regular
- Posts: 633
- Joined: Thu Nov 27, 2003 5:02 am
- Location: Israel - the best place to live in after heaven
- Contact:
nice trick:)
and limit is in MYSQL i think
-
ianlandsman
- Forum Newbie
- Posts: 24
- Joined: Thu Dec 30, 2004 9:50 pm
- Location: New York
Well I would probably just do this:
oh just realized that wyred posted this. oh well I'll post it anyway.
Code: Select all
SELECT num FROM table ORDER BY id DESC LIMIT 0,1