Create MySQL table by using another table

0

Create MySQL table based on one or more existing tables.

Here we create a new table called TempCustomer for Customers.

CREATE TABLE TempCustomer AS SELECT first_name, last_name FROM ExternalCustomer AS c  WHERE c.create_date >= ‘8/1/2015’;

In the above query, a new table named TempCustomer is created from the external customer table. Only customers created after August 2015 are included, but you can also import all customers from External Customer with no WHERE clause. We’re creating a TempCustomer table because we don’t want to import data directly into a production table before we review the query data and sample the information.

Take a look at the following query:

CREATE TABLE TempCustomer AS

SELECT c.first_name, c.last_name, a.address

FROM ExternalCustomer AS c

INNER JOIN ExternalAddress AS a

ON c.customer_id = a.customer_id

WHERE c.create_date >= ‘8/1/2015';

Above Query Using LEFT JOIN

CREATE TABLE TempCustomer AS

SELECT c.first_name, c.last_name, a.address

FROM ExternalCustomer AS c

LEFT JOIN ExternalAddress AS a

ON c.customer_id = a.customer_id

WHERE c.create_date >= ‘8/1/2015';