You are on page 1of 1

SQL 

INSERT INTO SELECT Statement


To copy data from one table and to insert the copied data into another table, the INSERT INTO SELECT
statement is used. Data types in both source and target table should match and it should not affect the
existing records of the target table.
INSERT INTO SELECT Syntax:
To copy all columns from one table to another table:

INSERT INTO table2
SELECT * FROM table1
WHERE condition;
To copy only some columns from one table into another table:

INSERT INTO table2  (column1, column2, column3,...)
SELECT column1, column2, column3, ...
FROM table1
WHERE condition;

The SQL CASE Statement


This statement works like other programming languages if-else statement. Going through the conditions it
tries to meet them. If the first condition is met, it will stop reading and will return a result. If it doesn’t
find any condition true, it returns value in ELSE condition.
CASE Syntax():

CASE
    WHEN condition1 THEN result1
    WHEN condition2 THEN result2
    WHEN conditionN THEN resultN
    ELSE result
END;

You might also like