Simple MySQL query searched

subster

Elite Member
Joined
Apr 5, 2008
Messages
2,157
Reaction score
1,527
Hi there,

there must be a simple query to run that changes field B to 1 if field A = 1.
I guess it something with a WHERE clause, but I am not really knowledged in MySQL.


Basically I want to do the following:

in table product_attributes where options_values_id = 1 change sortorder to 1 (value of the field)

Thanks for your help!
 
Code:
UPDATE product_attributes SET fieldB=1 WHERE fieldA=1
 
Thanks & Rep for quick help!
 
Oh, may I ask another query- This is a bit more difficult (and the las t I will ask for):

In table ABC: If field A1 = 2 ADD 'text123' at the beginning of the values inside field B1

Example:

Field B1 before query: blablabla
Field B1 after the query if A1 =2: text123 blablabla

Perhaps I am lucky enough again to gain your help
 
Oh, may I ask another query- This is a bit more difficult (and the las t I will ask for):

In table ABC: If field A1 = 2 ADD 'text123' at the beginning of the values inside field B1

Example:

Field B1 before query: blablabla
Field B1 after the query if A1 =2: text123 blablabla

Perhaps I am lucky enough again to gain your help

Code:
UPDATE ABC SET B1 = 'text123 ' + B1 WHERE A1=2
 
Hm - Thank you for your help.
phpMyAdmin does the query successfully, but unfortunately I have now only 0 in all that fields (B1 where A1=2)
 
Hmmm, what platform are you using? im assuming that you;re using mssql that's why i suggest to use "+", but it will depend on what platform you're using..maybe, try madoctopus suggestion :)

The query is correct, but concatination will depend on what platform you're using..
 
MO: that did it perfectly!

I am afraid i have the next question i cant answer mysql through the docs...

everything plays in the same table: wipe the value of field B, and copy the value of field A into B after that.

aying, thought so. But am using mysql. I am sorry if I did not mention this. repped both of you for willingness to help. Thanks again!
 
Last edited:
Code:
UPDATE ABC SET B = A

You dont whipe and then copy A to B. You just override B with what's in A. No need for 2 steps.

And add WHERE clause if you need to apply just on some records. This is all basic SQL man you should learn SQL. I don't mind helping people but this is so basic that i'm thinking you just too lazy to learn basic SQL.
 
yeah, you are right. I am asking for help as this is a field which i do need just in very few cases like this. one task to fullfill and then months nothing. so motivation to learn the basics is low to be honest.
I hope you dont take it as a bad habit. For example if you guess one title tag in your on page seo leads in a performance loss of the page, you just ask for an optimization of this 125 chars and dont do the whole on page course. please correct me if you think my point of view is wrong. i just know my talents abd i will never be a talented database manager or coder as i am just to untidy for that.
 
Back
Top