+ 3
How to use INSERT with WHERE clause
SQL
3 ответов
+ 15
INSERT statement is used to insert fresh row of data into a table and WHERE statement is used to set condition to filter data.
Eg: INSERTING DATA INTO STUDENTS TABLE
INSERT into students
value (178, Ani, CS);
-> here we inserted data into a table with three columns student_id, name and subject.
WHERE CAN BE USED WITH ALMOST EACH AND EVERY QUERY
eg:
SELECT * FROM students
WHERE student_id=178;
-> here from all the students data only the student having a particuler id will be selected.
-> WHERE can be used with other operators for filtering data.
+ 15
You can use it only in combination with SELECT.
Could you please explain, what are you trying to do? Why do you need the WHERE clause?
+ 3
I have used it for appending specific TableB data into TableA.
TableA
id name age
1 eric 20
2 lydia 25
TableB
id name age
3 tanya 28
4 genie 30
INSERT INTO TableA
SELECT id, name, age
FROM TableB
WHERE age < 30;
RESULT
id name age
1 eric 20
2 lydia 25
3 tanya 28