# 这个查询如何写，求指点

Kingofcode 2015-11-20 09:14:58

``````
--table a
--id1,name1,remark1
--1,	n1,	r1
--2,	n2,	r2
--3,	n3,	r3

--table b
--id2,name2,remark2
--b1,	bn1,	br1
--b2,	bn2,	br2
--b3,	bn3,	br3
--b2,	bn4,	br5
--b3,	bn5,	br6
--b2,	bn7,	br5
--b3,	bn8,	br6
``````

...全文
120 点赞 收藏 8

8 条回复

zbdzjx 2015-11-20

``````Select a.*,b.name2 from
(select * from a where id1 in(1,2))a
full join
(select * from b where id2='b10')b
on 1=1``````

Yole 2015-11-20
a left join b a左联接b 试一下吧~

Kingofcode 2015-11-20

Kingofcode 2015-11-20

Kingofcode 2015-11-20
``````
Select a.*,b.name2 from a,b where a.id1=1 and b.id2='b2'

Select a.*,b.name2 from a,b where a.id1 in(1,2) and b.id2='b2'

Select a.*,b.name2 from a,b where a.id1=1 and b.id2='b10'

Select a.*,b.name2 from a,b where a.id1 in(1,2) and b.id2='b10'

id1         name1      remark1              name2
----------- ---------- -------------------- ----------
1           n1         r1                   bn2
1           n1         r1                   bn4
1           n1         r1                   bn7

(3 行受影响)

id1         name1      remark1              name2
----------- ---------- -------------------- ----------
1           n1         r1                   bn2
1           n1         r1                   bn4
1           n1         r1                   bn7
2           n2         r2                   bn2
2           n2         r2                   bn4
2           n2         r2                   bn7

(6 行受影响)

id1         name1      remark1              name2
----------- ---------- -------------------- ----------

(0 行受影响)

id1         name1      remark1              name2
----------- ---------- -------------------- ----------

(0 行受影响)

``````

spiritofdragon 2015-11-20

Kingofcode 2015-11-20

Kingofcode 2015-11-20
@zbdzjx 的回答结果正确，已结贴

2.1w+

MS-SQL Server 疑难问题

2015-11-20 09:14