Database Reference
In-Depth Information
Tip
Column Names in INSERT SELECT This example uses the same column names
in both the INSERT and SELECT statements for simplicity's sake. But there is no
requirement that the column names match. In fact, MariaDB does not even pay attention
to the column names returned by the SELECT . Rather, the column position is used, so
the first column in the SELECT (regardless of its name) is used to populate the first
specified table column, and so on. This is useful when importing data from tables that
use different column names.
The SELECT statement used in an INSERT SELECT can include a WHERE
clause to filter the data to be inserted.
Note
More Examples Looking for more examples of INSERT use? See the example table
population scripts (described in Appendix B, “The Example Tables”) used to create the
example tables in this topic.
Summary
In this chapter, you learned how to use INSERT to insert rows into a database
table. You learned several other ways to use INSERT , and why explicit col-
umn specification is preferred. You also learned how to use INSERT SELECT
to import rows from another table. In the next chapter, you learn how to use
UPDATE and DELETE to further manipulate table data.
 
 
Search WWH ::




Custom Search