请教两张表的联合查询问题
有两张表,表1内容如下:
name test
---- ----
A 1
B 2
C 3
D 4
E 5
F 6
G 7
表2内容如下:
name value
-----------
C 1.HTM
E 2.HTM
F 3.HTM
G 4.HTM
C 7.HTM
E 2.HTM
D 3.HTM
G 4.HTM
A 1.HTM
B 2.HTM
E 3.HTM
F 4.HTM
现在得到结果A表全部,B表name=A表name的任意一条记录如:
name test value
---- ---- ----
A 1 1.HTM
B 2 2.HTM
C 3 7.HTM
D 4 3.HTM
E 5 3.HTM
F 6 4.HTM
G 7 4.HTM
请问用sql语句怎么实现?
------解决方案--------------------select a.name,test,min(value) value from A Inner Join B on a.name=b.name group by a.name,test
------解决方案--------------------select *, value=(select max(value) from B where name=A.name) from A
------解决方案--------------------使用内连接
select * from A
inner join b on A.name=B.name
------解决方案--------------------select A.name,test from A
inner join B on A.name=B.name
group by name,test
------解决方案--------------------随机的:
select name,test,value=(select top 1 value from b where name=a.name order by newid()) from a
------解决方案--------------------随机的:
select name,test,value=(select top 1 value from b where name=a.name order by newid()),n多内容 from a
------解决方案--------------------select A.name,test from A
inner join B on A.name=B.name
group by name,test
------解决方案--------------------select a.name,test,value,字段1,n多
from a
Inner Join
(select name,min(value) value,min(字段1) 字段1 ,n多 from b group by name) c
On
a.name=c.name