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
Related
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 ,
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 2 years ago.
Improve this question
I am able to navigation between a php page using ID but not using project name. Can you only use an number and not characters?
Works
$sql = "SELECT id, assigned, project, start, end, status
FROM projects
WHERE id=$id";
'.$row['project'].'
page url: https://example.com/project.php?id=1
Doesn't work
$sql = "SELECT id, assigned, project, start, end, status
FROM projects
WHERE project=$project";
'.$row['project'].'
page url: https://example.com/project.php?project=Test
Thanks for the help!
MySQL uses single or double quotes for strings. Your second query puts string to a query, resulting in invalid query.
This is not a valid SQL query:
SELECT `name` FROM `cats` WHERE `breed` = ordinary cat
But this is:
SELECT `name` FROM `cats` WHERE `breed` = 'ordinary cat'
Of note, be careful with using any input (including query string) in your query like you did. You should use prepared statement instead to safely escape that string for your query.
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%'
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
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 a query that is returning a different amount of user_id's each time it's run (based on the number of subscribers).
What I need to do is insert each of these user_id results into separate rows within a table along with a simple message of "new alert" in a separate column.
How could I possibly go about doing this? Would a for each loop work in this situation?
Try this:
INSERT INTO alert_table SELECT user_id, 'new alert' FROM ... WHERE ...
Use your own query, just prepend it with the INSERT INTO alert_table clause.