Databases| SQL| MySQL| Questions?

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials

Latest Questions
Comments
 
 
 


 

Mysql Merge

                         

Mysql Merge Statement is used to merge the two sql statement using UNION clause.The UNION clause is used to combine the result set of any two sql queries.

Understand with Example

The Tutorial covers you an example in 'Mysql Merge Statement'. To grasp this example we create a table 'employee01' and 'employee02' with required fieldnames and datatype respectively. To note, The Engine Value should be same in both the tables to merge them. The UNION clause will not work if the Engine value is different in both the tables.

 

 

 

Query to create table name employee01:

mysql> CREATE TABLE employee01 (
    ->              Empid int(10),
    ->              name varchar(30),
    ->              date date
    ->
    ->            )ENGINE=MyISAM;
Query OK, 0 rows affected (0.03 sec)

Query for inserting data in table name employee01:

The Query insert into is used to add the records or rows to the table' employee01'

mysql> insert into employee01(Empid,name,date)values('001','Girish','2009-01-06');
Query OK, 1 row affected (0.00 sec)
mysql> insert into employee01(Empid,name,date)values('002','Komal','2009-01-05');
Query OK, 1 row affected (0.02 sec)
mysql> insert into employee01(Empid,name,date)values('002','Mahendra','2009-01-04');
Query OK, 1 row affected (0.00 sec)

Query for viewing data of table named employee01:-

mysql> select * from employee01;
+-------+----------+------------+
| Empid | name     | date       |
+-------+----------+------------+
|     1 | Girish   | 2009-01-06 |
|     2 | Komal    | 2009-01-05 |
|     2 | Mahendra | 2009-01-04 |
+-------+----------+------------+
3 rows in set (0.00 sec)

Query to create table name employee02 :

mysql> CREATE TABLE employee02 (
    ->              Empid int(10),
    ->              name varchar(30),
    ->              date date
    ->            )ENGINE=MyISAM;
Query OK, 0 rows affected (0.03 sec)

Query for inserting data in table name employee02:

The insert into is used to add the records or rows to the table 'employee02'.

mysql> insert into employee02(Empid,name,date)values('001','A','2009-01-06');
Query OK, 1 row affected (0.00 sec)
mysql> insert into employee02(Empid,name,date)values('002','B','2009-01-05');
Query OK, 1 row affected (0.00 sec)
mysql> insert into employee02(Empid,name,date)values('003','C','2009-01-04');
Query OK, 1 row affected (0.01 sec)
mysql> insert into employee02(Empid,name,date)values('004','D','2009-01-03');
Query OK, 1 row affected (0.01 sec)
mysql> insert into employee02(Empid,name,date)values('005','E','2009-01-02');
Query OK, 1 row affected (0.00 sec)
mysql> insert into employee02(Empid,name,date)values('006','F','2009-01-01');
Query OK, 1 row affected (0.00 sec)

Query for viewing data of table named employee02:

mysql> select * from employee02;
+-------+------+------------+
| Empid | name | date       |
+-------+------+------------+
|     1 | A    | 2009-01-06 |
|     2 | B    | 2009-01-05 |
|     3 | C    | 2009-01-04 |
|     4 | D    | 2009-01-03 |
|     5 | E    | 2009-01-02 |
|     6 | F    | 2009-01-01 |
+-------+------+------------+
6 rows in set (0.00 sec)

Query to create table named Emptotal which is the merging of both the table name employee01 and employee02 :

The Query create a table 'Emptotal' that is the outcome merging of two table 'employee01' and 'employee02'.The UNION operator combine the result of two independent queries.

mysql> CREATE TABLE Emptotal (
    ->              Empid int(10),
    ->              name varchar(30),
    ->              date date
    ->            ) ENGINE=MERGE UNION=(employee01,employee02) ;
Query OK, 0 rows affected (0.03 sec)

Query for viewing data of merged table named Emptotal:

mysql> select * from Emptotal;
+-------+----------+------------+
| Empid | name     | date       |
+-------+----------+------------+
|     1 | Girish   | 2009-01-06 |
|     2 | Komal    | 2009-01-05 |
|     2 | Mahendra | 2009-01-04 |
|     1 | A        | 2009-01-06 |
|     2 | B        | 2009-01-05 |
|     3 | C        | 2009-01-04 |
|     4 | D        | 2009-01-03 |
|     5 | E        | 2009-01-02 |
|     6 | F        | 2009-01-01 |
+-------+----------+------------+
9 rows in set (0.00 sec)

                         

» View all related tutorials
Related Tags: sql mysql c string com sed char compare operator using opera character like cte to ld e il li use

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Training Courses
Tell A Friend
Your Friend Name
Software Solutions
Least Viewed
Most Rated
Recently Viewed
Search Tutorials

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Flex Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.