SQL UPDATE table with more than 1 word fail [closed] - php

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
my table "list_article_groups have several groups which is the same, but have different spellings and small differences that cause duplicates in system. So I want to join (seach and replace) all the duplicates.
I am running this expression;
UPDATE `list_articles_groups`
SET `name` = replace(name, '%front%cable%', 'Front cable')
But I get 0 result. If I replace % with space, i get 1000 results. Any clues?

Run this, ltrim and ltrim work with most sql plateforms. What is yours and we can adjust the code below
for sql server
UPDATE list_articles_groups
SET name = 'Front cable' where name like '%' + 'front' + '%'+ 'cable' + '%'
for postgres
UPDATE list_articles_groups
SET name = 'Front cable' where name like '%' || 'front' || '%'|| 'cable' || '%'.
You get the idea.

I found the solution. Using "where".
UPDATE list_articles_groups
SET name = 'Front Cable' WHERE name LIKE '%front%cable%'

Related

Find and replace phpMyAdmin [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 10 months ago.
Improve this question
I have around 20k URLs using this pattern bellow and I am trying to replace and remove this
fffd8ca225794d4c3c9f33a2ec321828of these URLs using phpMyAdmin
This is just an example, all these strings are random
What it is
https://www.xxxx.com/file/0/fffd8ca225794d4c3c9f33a2ec321828/740000/740640/screenshots/1.jpg
What I need
https://www.xxxx.com/contents/sources/740000/740640/screenshots/1.jpg
Could someone help me?
You can use simple UPDATE query with REPLACE function:
UPDATE <your table name>
SET <your field name> = REPLACE(
<your field name>,
'fffd8ca225794d4c3c9f33a2ec321828/', -- find this substring
'' -- replace by empty string
);
Test MySQL REPLACE online
Since MySQL 8.0 you can use REGEXP_REPLACE function
UPDATE urls SET url = REGEXP_REPLACE(
url,
'file/0/[a-z0-9]+/', 'contents/sources/
');
MySQL REGEXP_REPLACE test

Laravel eloquent Select statement set null column defualt value to 0 or blank [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
I am creating a query and executing it in my project. I want to set null column value to 0 in select statement.
We need to set null to blank or zero. See below screenshot
I think you can use model casting, using "if" statement https://laravel.com/docs/8.x/eloquent-mutators#custom-casts
UPDATE table_nameSETcolumn_name = 0 WHERE column_name is NULL
Edit: You can add as many columns as needed by adding a comma ,

Query db with in exlusion [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
Trying to query db. I need to show all fields, but need to exclude one name that is in the db.
Example:
The db contains column 'marketer' when I try to query it I don't want marketer 'Tommy' but all the others. I have tried tried where clause with all the names and not working.
This is the query you're looking for
SELECT * FROM <table_name> WHERE marketer<>'Tommy';
use the 'where' to add your conditions
SELECT * FROM your_table WHERE marketer!='Tommy'
For your Reference
http://www.w3schools.com/sql/sql_where.asp

how to add quotes to a search string for an exact match? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have some code here for a song request program. And it works just fine other than the user has to use surrounding quotes for an exact match. I am wondering how I would go about having the php add the quotes so the user can type a band or song title as normal without having to read the small help notice saying to use quotes?
You can concate quotes in after if you like.
$termToSearch = '"' . $termFromUser . '"';
$query = 'SELECT * FROM table WHERE song = :song'
$statement = $this->db->prepare($query);
$statement->bindValue(':song', $termToSearch);
$statement->execute();
$statement->closeCursor();
Just use "=" instead of "LIKE"
SELECT * FROM table WHERE column = '$searchterm'

All under MySQL_Error() are disappear [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I have a problem with disappearing my mysql_error and 50% of my website under error...
MySQL_Query("UPDATE table
SET use = '1'
WHERE name = '$code'", $SpojenieWeb) or die(mysql_error());
Why it is disaappearing ? Where is the error ?
Why it is disaappearing?
It's disappearing because most probably your UPDATE query fails and you use die() in case of failure.
Now it's really hard to say exactly since you provided not enough information, but looking at you query you at least have to change
"UPDATE table SET use = '1' WHERE name = '$code' ..."
to
"UPDATE `table` SET `use` = '1' WHERE name = '$code' ..."
^ ^ ^ ^
table and use are reserved words in Mysql

Categories