UPDATE first record

hamid

Well-known member
Joined
Jul 13, 2004
Messages
113
Hi,
i want to update first record founded by WHERE statement?
like as LIMIT but in vs.net and access database
 
!
look
Name Value
n1 1
n2 2
n3 3
n1 4
so, i want change Value for first n1 to 6:
UPDATE table1 SET n1=6
ok? but it set both n1 equal 6
how can i limit UPDATEed record to one record?
 
Does it matter which n1 would get updated? If you executed the update multiple times would it always be required to update the same one?

Is there the possibility that on some occasions you would want to update a (some) value(s) other than the first one?
 
i dont like use stupid ways for solve the problems ;)
anyone?

stupid huh ... :rolleyes:

right on then ...

Updating specific records requires specific criterias right? Since I never know anything like LIMIT to update records then I believe you should use that specific criterias.

Your first query should be UPDATE Table1 SET Value=6 WHERE Name=n1. Adding to that would be UPDATE Table1 SET Value=6 WHERE Name=n1 AND Value=1.

The fact is Im not trying to act stupid here. Im trying to say that youll be needing something unique when updating one specific records. This is why I dont see adding a new auto_increment column would be stupid.

That is all I suppose.
 
hamid,

I think youve got two options:
1. Include everything you can in your WHERE clause to limit the update to one row. amirs suggestion should work for you for the sample data your provided:
[highlight=sql]UPDATE Table1 SET Value=6 WHERE Name=n1 AND Value=1.[/highlight]

2. Add a primary key to the table - something that will uniquely identify every row. Unless you dont have access to change the table, Im not sure why you wouldnt want to do this. Having a primary key on every table is standard practice - most database engines will even warn you when creating tables without one.


-ner
 
Back
Top