日期:2014-05-17 浏览次数:20513 次
SELECT a.id,a.NAME,b.dept,b.age
FROM tabelA a
INNER JOIN tableB b
ON a.NAME = b.dept
create table testA(id nvarchar(10),name nvarchar(10))
insert into testA values('001','xxx')
create table testB(dept nvarchar(10),age int)
insert into testB values('xxx',33)
select *
from testA a
INNER JOIN testB b
on a.name=b.dept
/*
id name dept age
001 xxx xxx 33
*/
SELECT MAX(id)id,MAX(name) NAME,MAX(dept)dept,MAX(age)age
FROM (
SELECT id,NAME,NULL dept,NULL age
FROM tb1
UNION ALL
SELECT NULL,NULL,dept,age
FROM tb2)a