Thursday, January 30, 2014

How to implement this in SQL?


create table table1 (Field1 char(1),field2 char(1),Field3 int)
insert into table1 values('A','B',10),('A','c',20)

create table table2 (Field2 char(1))
insert into table2 values('B'),('C'),('D')

select t.field1,t.field2,t1.field3 from (select distinct a.Field1,b.Field2 from table1 a,table2 b) t
left join table1 t1 on t.field1=t1.field1 and t.field2=t1.field2


No comments:

Post a Comment