How do i edit multible rows in mysql based on a set of criteria [closed] - mysql

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 months ago.
Improve this question
I have a mysqlp table which contains a set of data as in the sample excel file. We need a query that will copy the product name into the customer field where customer = Luxury. We used the below query to start editing one by one but there are thousands of records.
SET customer = 'TAVERNAKI' WHERE product = 'TAVERNAKI' AND customer = 'LUXURY';
So we are going about copying and pasting the query and replacing the product name each time. Does anyone have an idea for a mass edit of all records?
Sample file in the link here
[1]: https://docs.google.com/spreadsheets/d/1sgtwNobMU5mKCLuxDLqhpEivEekI0l4R/edit?usp=sharing&ouid=107367920163394089177&rtpof=true&sd=true

Simply
UPDATE table SET customer=product WHERE customer='Luxury'

Related

Want to change prefix of values in mysql database [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 2 years ago.
Improve this question
I have millions of data in my database table customer. In that, I have the id_token attribute which has value like cus00001 format now I want to change it to ank00001.
What will be the query in rails or mysql to do it for all the data in the database?
You can use simple update query using REPLACE function:
UPDATE `table_name` SET `id_token` = REPLACE(`id_token`, 'ank', 'cus');

How to get the username from gmail and insert in the same table as different column in mysql [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I have a table named users. I have their email id in email column as "kayal#gmail.com", "suresh#yahoo.com", etc. I need a sql query to save the username(splitted from the email column like kayal, suresh, etc) column in the same existing table. How can I do this?
update users set username="SUBSTRING_INDEX(email, "#", 1)";
This made the trick.

Find if a string from one field is contained in another field on the same row and delete it if so [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
Say I have the following fields in each row
Make Model
Toyota Toyota Camry
I need a query that will check if the string in Make is also contained in Model and delete the portion of Model value that matches.
Perhaps this is what you're looking for with replace:
update yourtable
set model = replace(model, make, '');
SQL Fiddle Demo

Import a table so field is all lowercase [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
Not sure it is possible, but I am trying to import a large set of data and I want to make the cases for certain fields to be imported as all lowercase. I know how to do it once the data is loaded but it takes forever so was looking to do it as I imported it.
Thanks
Create a database trigger which will ensure that all characters are coverted to lowercase before storing in a particular filed
CREATE TRIGGER lc_ins BEFORE INSERT ON tablename FOR EACH ROW
SET NEW.fieldname = LOWER(NEW.fieldname);
CREATE TRIGGER lc_upd BEFORE UPDATE ON tablename FOR EACH ROW
SET NEW.fieldname = LOWER(NEW.fieldname);

MySQL select issue ( unique ) [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 a table with the following fields :
date / source / destination
The same source can go to the same destination but at different time.
Multiple sources can go to same destination, etc.
I am looking to extract all destinations that have unique sources.
Bit hard to try to help with so little info, but maybe this could work?
SELECT Destination
FROM tablename
GROUP BY Destination
HAVING COUNT(DISTINCT Source) = 1