How to use INSERT with WHERE clause | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

How to use INSERT with WHERE clause

SQL

4th Jun 2019, 11:43 PM
Prince Ani Frimpong
Prince Ani Frimpong - avatar
3 Answers
+ 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.
7th Jun 2019, 12:52 AM
Night_fury~
Night_fury~ - avatar
+ 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?
6th Jun 2019, 10:04 PM
Igor Makarsky
Igor Makarsky - avatar
+ 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
6th Jun 2019, 10:16 PM
Ed Briones
Ed Briones - avatar