Page 1 of 1
latest data from table
Posted: Mon Sep 06, 2004 1:27 am
by g3ckO
I have a table something like below:
Code: Select all
user1 green approved
user2 black approved
user1 black pending
user1 green approved <------- this row
user2 black pending
How should I write the query to call the data on that row. In other word is to call the
user1 latest data (row) on that table.
Posted: Mon Sep 06, 2004 2:09 am
by feyd
is there any other data to sort by?
Posted: Mon Sep 06, 2004 2:13 am
by g3ckO
feyd wrote:is there any other data to sort by?
what do you mean?
There is other fields like userID, name, unit and so on but all the data are same for each user everytime the data is store into database.
Posted: Mon Sep 06, 2004 4:16 am
by m3mn0n
This db layout doesn't seem very organized. Either that or your explaination is a bit off. Either that or I need some sleep.

Posted: Mon Sep 06, 2004 4:22 am
by g3ckO
Ok. I think this is more easy to understand.
If we have duplicate data in one table, how can we write the query to call the latest one.
Posted: Mon Sep 06, 2004 4:23 am
by m3mn0n
Timestamp the entires. Or go by highest userID/entryID or whatever.
Posted: Mon Sep 06, 2004 4:34 am
by g3ckO
Sami wrote:Timestamp the entires.
How to use timestamp?
I ask the user to enter the date and it will be store in db in this format
yyyy-mm-dd
can I use this info to call the latest data. How the query will look like?
Posted: Mon Sep 06, 2004 4:59 am
by timvw
You should not allow the user to input the timestamp.
If you are using MySQL use NOW() instead.
This way if you SELECT the rows, you can ORDER them BY timestamp DESC and LIMIT the resultset to 1 row
Posted: Mon Sep 06, 2004 6:59 am
by jason
Posted: Mon Sep 06, 2004 9:13 pm
by g3ckO
That means, I just need to add another field for timestamp. But how can I insert the value into that field?? Never use timestamp before..
Posted: Mon Sep 06, 2004 9:37 pm
by m3mn0n
Well when in doubt about something, Google it.
It would lead you to a page like the one jason linked to, or this one: [php_man]time[/php_man]()
Posted: Mon Sep 06, 2004 10:08 pm
by g3ckO
Sami wrote:Well when in doubt about something, Google it.
I have read and google it
Sami
But I still cannot understand it. Most of the explaination are too confusing

It doesn't show any simple example for me to understand.
I need to know how the timestamp will be inserted to the field that I created and how to call the latest data in my query.
Can you show me the example of the query or just suggest another link for me to google it

Posted: Mon Sep 06, 2004 10:15 pm
by feyd
try here: [mysql_man]date time function[/mysql_man]you'll potentially want [mysql_man]UNIX_TIMESTAMP[/mysql_man] and [mysql_man]NOW[/mysql_man] to insert the data.. and simple ORDER BY field_name DESC to get the newest ones first.
Posted: Tue Sep 07, 2004 12:55 pm
by Draco_03
I would suggest you to create a primary key auto increment (id) AND a timestamp.