Find and replace with MySQL version 5.5.3 - mysql

I am trying to find a weird character thats in front of my £ sign and replace it with nothing.
Coding I tried was
update [orders_total]
set [text]=replace([text],'[Â]','[]');
but mysql returns this
1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use
near '[orders_total] set [text]=replace([text],'[Â]','[]')' at line 1
I know nothing of Mysql but its going to take me ages to manually remove these chars so any help would be much appreciated.
Thanks in advance

Thats not mysql syntax and in mysql it should be as
update orders_total
set text=replace(text,'Â','');

Abhik is absolutely right in his answer. An alternate form of writing MySQL queries is:
update `orders_total` set `text` = replace(`text`, '..', '...');
Backticks are not required. They may be valuable when a table's column is named order, for example. Order is a reserved keyword used in order by ... clause. In order to use a reserved keyword like order, use backticks.
Example:
select `order`, `id`, ... from `tablename` where .... order by `order`;

Related

STRING_SPLIT in MySql- how to do it?

SELECT er.pNumber, er.name, ep.fPosition, eo.res
FROM events_shot er, events_shot_final ep, events_shot_final_res eo, events_gear era
WHERE era.idShot=er.idShot AND ep.idPhoto=era.idPhoto AND eo.idShot=era.idShot
AND era.idShot=42 AND eo.shotType='PRT'
AND er.pNumber IN (
SELECT *
FROM STRING_SPLIT(eo.photosId,'-')
)
shotsId is a String like 12-1-8-7... with n pNumber id separated by '-'
Unfortunately the query return this error:
Error Code: 1064. You have an error in your SQL syntax; check the
manual that corresponds to your MySQL server version for the right
syntax to use near '(eo.photosId,'-') )' at line 7
I can't change the database, how can I change my query?
Any help you can provide would be appreciated.
Fix your data model! Don't store multiple values in a single column.
Learn proper SQL syntax! Never use commas in the FROM clause. Always use proper, explicit, standard JOIN syntax.
With that said, you don't need to split the string. You can use string operations:
AND CONCAT('-', eo.photosId, '-') LIKE CONCAT('%-', er.pNumber, '-%')
But you should really start work on fixing the data model as soon as you get this query to work.

Syntacts error in mysql query

Someone gave me this query to delete community from a database on my server using phpMyAdmin, it worked when he use it so I asked him to send it to me, but I get a error
MySQL said:
Documentation
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '"SELECT * FROM `connections` WHERE 1" :
delete from connections where communit' at line 1
I did a search on the error but could not figure it out.
"SELECT * FROM `connections` WHERE 1" :
delete from connections where community="XYZ"
You should separate your queries with ; and not :
The error you are receiving as you've shown it is because this line is incorrect:
SELECT * FROM `connections` WHERE 1"
First because it's ending in an unnecessary double quotation mark. MySQL does not use double quotes but single quotes, and even still the other single quote is not there to match it.
The single quotes are also a problem for community="XYZ", this should read: community = 'XYZ'
Secondly, you don't have a condition for your where statement, you must be missing something like:
WHERE columnName = 1;
If you were trying to select everything from connections, you can just remove that where clause all together.
EDIT
In addition, MySQL queries are separated by a semi-colon, not a colon, so MySQL will not realize you are trying two different queries.

MYSQL: Check if table exists does not work

IF OBJECT_ID(N`db_291702_2`.`aaCoRrankingDateManage`, N'U') IS NOT NULL
BEGIN
PRINT 'Table Exists'
END
What is wrong with this? Why do I get errors?
Neither of the suggested ways in how-to-check-if-a-table-exists-in-sql-server/ works for me.
PS. "does not work" means errors like
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''db_291702_2'.'aaCoRrankingDateManage' LIMIT 0, 30' at line 1
Additional info:
I am using phpMyAdmin, my two databases are called db_291702_1 and db_291702_2, the latter has two tables, one of them is called aaCoRrankingDateManage
If you want to escape table or column names then use backticks
select `group` from table1
A static string must be included in quotes
select * from users where name = 'john'
And the syntax of every DB engine is a little bit different. The above works for MySQL, but SQL-Server has a different syntax. There you use brackets [] to escape names.
But you only need to escape names if you use reserved words. You don't have to escape everything.
The given source code is no MySQL Code.

Correct format to use regex in MySQL SELECT statement (not within WHERE section)

I need to use REGEX (or similar functiuonality) to update an existing table in order to identify if a string field contains a correctly formatted code:
UPDATE tblRequests SET flagIsRefCodeOK=(RefCode REGEX '^[A-Z0-9]{8}-(?:[A-Z0-9]{4}-){3}[A-Z0-9]{12}$') WHERE DataSetID=11
But it doesn't seem to like the statement:
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'REGEX '^[A-Z0-9]
Note, this code will be added to a BEFORE INSERT trigger, which is responsible for updating a number of flags. I'm not fussed (much) with whether the REGEX is correct, especially within MySQL, I just want it to try to work. Then I'll figure out the exact REGEX if this doesn't work.
Thnx
The operator name is REGEXP not REGEX, so try:
UPDATE tblRequests
SET flagIsRefCodeOK= (RefCode REGEXP '^[A-Z0-9]{8}-(?:[A-Z0-9]{4}-){3}[A-Z0-9]{12}$')
WHERE DataSetID=11;

MySQL query sanity check, for update query

I have this query
update user_remember_me set
when='2012-07-06 05:44:27',
hash='c8e9d2c0dd156b5c68d0b048e5daa948e6b8fac7'
where user = '21';
and I am getting this error
Error : You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'when='2012-07-06 05:44:27', hash='c8e9d2c0dd156b5c68d0b048e5daa948e6b8fac7' wher' at line 1
Im failing to miss the connection here, I've used simple updates like this everywhere without issue til this, maybe Im getting to tired, but this is gonna drive me nuts til I have an answer
When is a key word in mysql, change the column name
or you can use it as
`when`='2012-07-06 05:44:27'
when is a reserved word in mysql
update user_remember_me set
`when`='2012-07-06 05:44:27',
`hash`='c8e9d2c0dd156b5c68d0b048e5daa948e6b8fac7'
where user = '21';
So you must backtick your column
when is a keyword within MySQL. You have to escape it, if you want to use it as a column identifier (as you should with all column identifiers!):
UPDATE user_remember_me
SET
`when`='2012-07-06 05:44:27',
`hash`='c8e9d2c0dd156b5c68d0b048e5daa948e6b8fac7'
WHERE `user` = '21';