472,974 Members | 1,721 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,974 software developers and data experts.

MySLQ, update by date/number

Hi,

I have a table with 3 columns, something like...

NAME, VALUE, DATE, (String(255), int(11), int(11)).

And for argument lets say the data is

row[0] = "A", 10, 1076968526
row[1] = "A", 10, 1076710733
row[2] = "A", 10, 1076709644

I want to update the row where the name = "A" and set the value to 11. But i
only want to update the latest date, (row[0]), in this case where DATE is
the higher.
How would i run a query to update a row where one on the value is the
highest.

Many thanks

Sims
Jul 17 '05 #1
2 2049
On Tue, 17 Feb 2004 07:44:10 +0200, "Sims" <si*********@hotmail.com>
wrote:
Hi,

I have a table with 3 columns, something like...

NAME, VALUE, DATE, (String(255), int(11), int(11)).

And for argument lets say the data is

row[0] = "A", 10, 1076968526
row[1] = "A", 10, 1076710733
row[2] = "A", 10, 1076709644

I want to update the row where the name = "A" and set the value to 11. But i
only want to update the latest date, (row[0]), in this case where DATE is
the higher.
How would i run a query to update a row where one on the value is the
highest.


According to:
http://www.mysql.com/doc/en/UPDATE.html

you should be able to write
update table set value=11 where name='A' order by date desc limit 1

but I haven't tried it.

There is a bit which explains differences in the behaviour of LIMIT
between MySQL versions. Check that carefully for your version.

--
David ( @priz.co.uk )
Jul 17 '05 #2
Each of those records should have a primary key, so after you have read the
record(s) in and decided which one you want to update it is a simple matter
of issuing the following query:
UPDATE table SET value='11' where pkey='value'.

If you will always want to update the record with the latest date then you
can ensure that it is returned as the first row with the following query:
SELECT * FROM table ORDER BY date DESC LIMIT 1

--
Tony Marston
http://www.tonymarston.net
"Sims" <si*********@hotmail.com> wrote in message
news:c0*************@ID-162430.news.uni-berlin.de...
Hi,

I have a table with 3 columns, something like...

NAME, VALUE, DATE, (String(255), int(11), int(11)).

And for argument lets say the data is

row[0] = "A", 10, 1076968526
row[1] = "A", 10, 1076710733
row[2] = "A", 10, 1076709644

I want to update the row where the name = "A" and set the value to 11. But i only want to update the latest date, (row[0]), in this case where DATE is
the higher.
How would i run a query to update a row where one on the value is the
highest.

Many thanks

Sims

Jul 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: laurie | last post by:
Hi all, I'm trying to help out a friend who has inherited a client with a PHP shopping cart application. Neither of us know PHP, but I've been muddling my way through, trying to get these old...
3
by: Ken Bush | last post by:
How can I write an update query that removes part of a field? Like if I have a field with values such as 8/3/68 (a birthday obviously) and I need to put values in a new column but I need...
3
by: Ray | last post by:
Any help? I have two tables. TABLE 1 one which shows all the days of the year with (Number) (date) Each day of the year (Yes/No) TABLE 2 with reservation details with (Autonumber)
8
by: Maxi | last post by:
There is a lotto system which picks 21 numbers every day out of 80 numbers. I have a table (name:Lotto) with 22 fields (name:Date,P1,P2....P21) Here is the structure and sample data: ...
7
by: aaron.kempf | last post by:
team so i have a nice little list in sharepoint.. about 15k items i've got the simplest little join statement in access; and im trying to UPDATE the sharepoint list via an access query. so...
0
by: M. David Johnson | last post by:
I cannot get my OleDbDataAdapter to update my database table from my local dataset table. The Knowledge Base doesn't seem to help - see item 10 below. I have a Microsoft Access 2000 database...
5
by: cover | last post by:
I have an input form that passes data when submitted to a second form to let the user know what they have just entered into the db. My question comes with using 'update'. I'd like to query the...
1
by: teenagelcruise | last post by:
hi, i have a problem with my code which is i cannot update and addnew data into the database but i can delete the data.plz give me an idea.this is my code that i wrote. <html> <head> <meta...
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.