On 08/13/2010 10:47 AM, erkin tek wrote:
assume *table* has *id,  value* rows

In mysql there is no special indicatior and we need to make funny things like

1) getting max valued row:
select * from table ,
(select max(value) from table ) as t
table.value=t.value

Assuming you really only want one row (there could be several rows with the same max. value after all):

select * from table order by value desc limit 1

2) last inserted row
select * from table order by id limit 1

What if you already have an entry with an id of say 5000 but then a script deletes some rows and re-uses the id's? "last inserted row" and "row with the highest id" are semantically different questions.
It would probably be better to add a date field and then do:

select * from table order by date desc limit 1

3) one random row
select * from table order by rand() limit 1


This is a slow method to get a random row. A solution you see mentioned often on the web is:

select max(id) as max_id from table
random_id = random(1,max_id)
select * from table where id >= random_id order by id limit 1

I think there could faster, elegant row methods  are required.
  like :
1) select maxrow(*) from table

There would be no way for drizzle to determine what you mean with maxrow(*). Do you mean the row where the id field is highest or where value is highest?

2) select lastrow(*) from table

When do you really actually want to get only the last inserted row? Usually "last" or "latest" means something in relation to the data you have stored in the table e.g. if you are processing orders you don't want the "last inserted row" but the "latest orders" which might actually be several ones depending on how many orders are coming in. Again the "lastrow(*)" syntax would be either not very useful or at least ambiguous.

3)select randomrow(*) from table

My question is :
are There such methods?
if not, will there be such methods?

_______________________________________________
Mailing list: https://launchpad.net/~drizzle-discuss
Post to     : [email protected]
Unsubscribe : https://launchpad.net/~drizzle-discuss
More help   : https://help.launchpad.net/ListHelp

Reply via email to