Monday, 4 July 2011

SQL insert into statement

Learn how to use insert rows in to a table .
Sql insert into statement
The Sql INSERT statement is used to insert a single record or multiple records into a table.
While inserting a row, if the columns are not specified, it means that vales are added for all of the columns of the table resulting addition of a single row. If it is required to insert values for one or more specific column(s), then it is necessary to specify the name(s) of the column(s) in the sql query.

Insert null


The SQL INSERT statement can also be used to insert NULL value for a column.

Insert for specific column
The SQL INSERT INTO statement can also be used to insert one or more specific columns for a row. It is required to mention the column(s) name in the sql query.

Inserting the result of a query in another table


All the rows or some rows of another table can also be inserted into the table using INSERT INTO statement. The rows of another table will be fetched based on one or more criteria using SQL SELECT statement.
Inserting the result of a query in another table using order by

An arranged order of rows (ascending or descending) of one table can also be inserted into another table by the use of SQL SELECT statement along with ORDER BY clause.

Inserting the result of a query in another table using group by
A group of rows of one table can be inserted into another table by the use of SQL SELECT statement along with GROUP BY clause. 


Inserting records using select with order by and group by
How records of another table can be inserted using SQL SELECT statement along with ORDER BY and GROUP BY in a INSERT INTO statement.

Insert using subqueries
Inserting rows of another table using subquery.

Insert using subqueries with where clause

How to insert rows using INSERT INTO statement, where rows are results of a subquery, made up of SQL SELECT statement with WHERE clause.

Insert using subqueries with any operator

How an ANY operator can participate in an INSERT INTO statement. 


Insert using subqueries with any operator and groupby

How an ANY operator with GROUP BY clause can participate in an INSERT INTO statement.

Insert using nested subqueries with any operator

How two or more subqueries can be implemented in an INSERT INTO statement to insert rows into a table.

Insert using nested subqueries with any operator and group by

How an ANY operator with GROUP BY can be used in an INSERT INTO statement to insert records in a table.

Insert using nested subqueries with any operator and group by and order by

How an ANY operator with ORDER BY and GROUP BY can be used in an INSERT INTO statement to insert records in a table.

Insert using subqueries with max function

How an MAX() function in a subquery can be used in an INSERT INTO statement to insert records in a table.