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 8 years ago.
Improve this question
I have a list of items in a table that have ids, and I want to put them into a item_to_group table, all with a specific group number.
My MySQL code is:
INSERT INTO `item_to_item_group` (`items`.`id`, 3476)
SELECT `id`
FROM `items`
But I'm getting the old "You have an error in your SQL syntax" message. Can anyone help? Thanks
No, it should be the column name instead of value,
INSERT INTO item_to_item_group (id, columnameHere) -- <== define columnName here
SELECT id, 3476
FROM items
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 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');
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.
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 5 years ago.
Improve this question
What is the syntax for a query to:
Search a table for all rows with a substring X within a certain column,
and replace the column in all the rows found with substring X removed.
Basically, I need to remove html tags that snuck into title sections.
Use the REPLACE() function in an UPDATE query.
UPDATE yourTable
SET title = REPLACE(title, 'substringX', '');
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 6 years ago.
Improve this question
I've a table "user" and another table "test"
My test table contains some of the userids. I want to check and insert into table "test" all those userids which are not there.
can you please help me with SQL query ?
thanks in advance
You may looking for this
INSERT INTO Test(Col1,col2..)
SELECT Col1,col2.. FROM UserTable WHERE UserTable.UserID NOT IN (SELECT UserID FROM Test)
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 7 years ago.
Improve this question
What is the most efficient mysql query to SELECT from a table IF a value already exists ELSE INSERT?
I have already tried several options but can't find something that works for me.
I'm new to Stackoverflow and dont know how to tag a question as duplicate.
But i think there is a really similar question with plenty of answers. Give a look here
[Possible solution]
You could insert if it not exists and then select it.
INSERT INTO Test(Key_Value , Name , ...) VALUES(#Key_Value ,#Name,..) WHERE NOT EXISTS (SELECT 1 FROM Test WHERE KeyValue = #KeyValue);
SELECT Name FROM Test WHERE Key_Value = #Key_Value