Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

!

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?

[ once4ever ]
  • Administrators
Posted

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?

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Posted
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.

Amir Syafrudin
  • *Experts*
Posted

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

"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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...