日期:2014-05-18 浏览次数:20778 次
create table t1
(
id int,
name varchar(10)
)
insert into t1
select 1,'蔬菜' union all
select 2,'水果' union all
select 3,'粮食' union all
select 4,'家禽' union all
select 5,'水产' union all
select 5,'副食'
create table t2
(
id int,
name varchar(10),
pname varchar(10)
)
insert into t2
select 1,'菠菜','蔬菜' union all
select 1,'韭菜','蔬菜' union all
select 1,'苹果','水果' union all
select 1,'香蕉','水果' union all
select 1,'橘子','水果' union all
select 1,'鸡','家禽' union all
select 1,'鸭','家禽'
select * from t1
select * from t2
select t1.name,isnull(t2.pname,'') as pname from t1 left join t2 on t1.name=t2.pname
-----------------------
name pname
蔬菜 蔬菜
蔬菜 蔬菜
水果 水果
水果 水果
水果 水果
粮食
家禽 家禽
家禽 家禽
水产
副食