hamid Posted March 19, 2007 Posted March 19, 2007 Hi, i want to update first record founded by WHERE statement? like as LIMIT but in vs.net and access database Quote [ once4ever ]
amir100 Posted March 20, 2007 Posted March 20, 2007 Okaaay ... This question is confusing. :p Quote Amir Syafrudin
hamid Posted March 20, 2007 Author Posted March 20, 2007 ! 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? Quote [ once4ever ]
amir100 Posted March 21, 2007 Posted March 21, 2007 A definite solution would be adding another column to act as a primary key. :D Quote Amir Syafrudin
hamid Posted March 21, 2007 Author Posted March 21, 2007 A definite solution would be adding another column to act as a primary key. i dont like use stupid ways for solve the problems ;) anyone? Quote [ once4ever ]
Administrators PlausiblyDamp Posted March 21, 2007 Administrators Posted March 21, 2007 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? Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
amir100 Posted March 22, 2007 Posted March 22, 2007 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 I'm not trying to act stupid here. I'm trying to say that you'll be needing something unique when updating one specific records. This is why I don't see adding a new auto_increment column would be stupid. That is all I suppose. Quote Amir Syafrudin
*Experts* Nerseus Posted March 22, 2007 *Experts* Posted March 22, 2007 hamid, I think you've got two options: 1. Include everything you can in your WHERE clause to limit the update to one row. amir's 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 don't have access to change the table, I'm not sure why you wouldn't 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 Quote "I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.