sql query to insert multiple records [closed] - mysql

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)

Related

MySql : How to delete multiple rows? [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 2 years ago.
Improve this question
How should I delete those two rows by using user_email and note_name only?
Please help
thank you
You can use this below delete script-
delete from your_table_name where user_email = 'asdf#....' and note_name = 'adsf'
Note: This will also delete other rows if there any matching for the conditions.

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.

Complex MySQL Join [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 7 years ago.
Improve this question
I struggle with a MySQL Join.
These are my tables:
user(id, name,...);
aim(id, title,...);
aim2user(userID, aimID);
A user can have multiple aims.
I would like to return all aims which are NOT selectet by user X.
How is this possible?
select id from aim where id not in (select zeildID from aim2user where userID=X)

MySQL if value exists select else insert [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 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

INSERT...SELECT FROM Mysql statement error [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 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