查看内容

两表合并查询澳门太阳集团2007网站

  • 2020-02-09 12:35
  • 数据库知识
  • Views

UNION 

UNION ALL

//Table Attribute 

Create table student(  

  id int unsigned not null auto_increment,

  name varchar(20) not null,

  primary key(id)

)ENGINE=InnoDb AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 ;

Create table student1(  

  id int unsigned not null auto_increment,

  name varchar(20) not null,

  primary key(id)

)ENGINE=InnoDb AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 ;

 

select id name from student

UNION ALL

select 0,name from student1

Output:

1     小明      

2  Jack  --->student

0  Tom     --->student1

0  Jack  --->student

 

select id name from student

UNION ALL

select id,name from student1

Output:

1     小明      

2  Jack  --->student

1  Tom     --->student1

2  Jack  --->student

 

select id name from student

UNION               ----<UNION>----

select id,name from student1

Output:

1     小明      

2  Jack  --->student

1  Tom     --->student1

Jack  is missing...............

上一篇:SQL技术内幕三 下一篇:SQL打印全年日历