Copying Only Selected Data from a Table : Copy Table « Table Index « SQL / MySQL

Home
SQL / MySQL
1.Aggregate Functions
2.Backup Load
3.Command MySQL
4.Cursor
5.Data Type
6.Database
7.Date Time
8.Engine
9.Event
10.Flow Control
11.FullText Search
12.Function
13.Geometric
14.I18N
15.Insert Delete Update
16.Join
17.Key
18.Math
19.Procedure Function
20.Regular Expression
21.Select Clause
22.String
23.Table Index
24.Transaction
25.Trigger
26.User Permission
27.View
28.Where Clause
29.XML
SQL / MySQL » Table Index » Copy Table 
Copying Only Selected Data from a Table
      
mysql> CREATE TABLE product(
    ->     cust_num MEDIUMINT NOT NULL AUTO_INCREMENT,
    ->     cust_title TINYINT,
    ->     cust_last CHAR(20NOT NULL,
    ->     cust_first CHAR(15NOT NULL,
    ->     cust_suffix ENUM('Jr.', 'II', 'III','IV', 'V''M.D.','PhD'),
    ->     cust_add1 CHAR(30NOT NULL,
    ->     cust_add2 CHAR(10),
    ->     cust_city CHAR(18NOT NULL,
    ->     cust_state CHAR(2NOT NULL,
    ->     cust_zip1 CHAR(5)NOT NULL,
    ->     cust_zip2 CHAR(4),
    ->     cust_duckname CHAR(25NOT NULL,
    ->     cust_duckbday DATE,
    ->     PRIMARY KEY (cust_num)
    -> );
Query OK, rows affected (0.00 sec)

mysql>
mysql> INSERT INTO product VALUES
    -> (NULL, 1'XML', 'Red', 'III', '1022 N.E. Sea of Rye', 'A207', 'Seacouver', 'WA', '98601', '3464', 'Netrek Rules'
'1967:10:21');
Query OK, row affected (0.00 sec)

mysql>
mysql> INSERT INTO product VALUES
    -> (NULL, 4'SQL', 'Vicki', 0'2004 Singleton Dr.', 0'Freedom', 'KS', '67209', '4321', 'Frida Kahlo de Tomayo',
'1948:03:21');
Query OK, row affected, warning (0.00 sec)

mysql>
mysql> INSERT INTO product VALUES
    -> (NULL, 9'HTML', 'Chantel', 0'1567 Terra Cotta Way', 0,  'Chicago', 'IL', '89129', '4444', 'Bianca', '1971:07:
29');
Query OK, row affected, warning (0.00 sec)

mysql>
mysql> INSERT INTO product VALUES
    -> (NULL, 7'Robert', 'David', 'Sr.', '20113 Open Road Highway', '#6', 'Blacktop', 'AZ', '00606', '1952', 'Harley',
 '1949:08:00');
Query OK, row affected, warning (0.00 sec)

mysql>
mysql> INSERT INTO product VALUES
    -> (NULL, 5'Kazui', 'Wonko', 'PhD', '42 Cube Farm Lane', 'Gatehouse', 'Vlimpt', 'CA', '45362', 0'Fitzwhistle', '
1961:12:04');
Query OK, row affected (0.00 sec)

mysql>
mysql> INSERT INTO product VALUES
    -> (NULL, 6'iPhone', 'Karen', 0'3113 Picket Fence Lane', 0,  'Fedora', 'VT', '41927', '5698', 'Tess D''urbervill
e', '1948:08:19');
Query OK, row affected, warning (0.00 sec)

mysql>
mysql> INSERT INTO product VALUES
    -> (NULL, 8'Mac', 'Jenny', 0'9 Wishing Well Court', 0'Meadowlark Hill', 'KS', '67048', '1234', 'Spike', '1961:
03:21');
Query OK, row affected, warning (0.00 sec)

mysql>
mysql>
mysql> CREATE TEMPORARY TABLE tempKS_list
    -> SELECT cust_num, cust_last
    -> FROM product
    -> WHERE cust_state LIKE "KS";SELECT *
Query OK, rows affected (0.00 sec)
Records: 2  Duplicates: 0  Warnings: 0

    -> FROM tempKS_list;
+----------+-----------+
| cust_num | cust_last |
+----------+-----------+
|        | SQL       |
|        | Mac       |
+----------+-----------+
rows in set (0.00 sec)

mysql>
mysql> drop table product;
Query OK, rows affected (0.00 sec)

mysql>

   
    
    
    
    
    
  
Related examples in the same category
1.Copy Table Demo
2.Copy Table with Condition
3.Copying a Table
4.Use NULL in where clause
5.Copy table with conditions
6.Only copy records
7.Using the INSERT Statement to Copy Data
8.Using the REPLACE Statement to Copy Data
9.Copy a table
10.Only copy certain columns
11.Copy one row of data
12.Copy data to temporary table
13.Creating New Tables with SELECT Results
14.Copy table with calculation
15.Copying Data into a New Table
16.MySQL truncates the data during copying
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.