22,206
社区成员
发帖
与我相关
我的任务
分享
table1
-------|------|------|------|------|------|------|------|--------------
solt0 |solt1 |solt2 |solt4 |solt5 |solt6 |solt7 |solt8 |solt9
-------|------|------|------|------|------|------|------|--------------
101 111 121 311 413 2341 1141 123 116
-------|------|------|------|------|------|------|------|--------------
501 101 567 897 145 190 782 124 212
-------|------|------|------|------|------|------|------|--------------
1123 2341 1245 216 316 210 219 34561 8431
-------|------|------|------|------|------|------|------|--------------
table 2 [id]是主键
------|------|--
id name
------|------|--
101 xxx1
------|------|--
1110 xxx2
------|------|--
121 xxx3
------|------|--
3110 xxx4
------|------|--
4113 xxx5
------|------|--
21341 xxx6
------|------|--
1141 xxx7
------|------|--
123 xxx8
------|------|--
116 xxx9
------|------|--
...省略 table2中id是table1中id的集合 .
问题是将table1中的solt与table2中的id相结合 找出相同项
现在想要的查询结果
------|------|--
id name
------|------|--
101 xxx1
------|------|--
111 xxxx
------|------|--
121 xxx3
------|------|--
311 xxxx
------|------|--
413 xxx5
------|------|--
21341 xxx6
------|------|--
1141 xxx7
------|------|--
123 xxx8
------|------|--
116 xxx9
------|------|--
501 xxxx
------|------|--
567 xxxx
------|------|--
897 xxx
------|------|--
145 xxxx
------|------|--
190 xxxxx
------|------|--
782 xxxx
------|------|--
... 省略
select *
from table2
where id in
(select solt0 solt from table1
union all
select solt1 from table1
union all
select solt2 from table1
union all
select solt3 from table1
union all
select solt4 from table1
union all
select solt5 from table1
union all
select solt6 from table1
union all
select solt7 from table1
union all
select solt8 from table1
union all
select solt9 from table1)
select b.*
from table2 b,
(select solt0 solt from table1
union all
select solt1 from table1
union all
select solt2 from table1
union all
select solt3 from table1
union all
select solt4 from table1
union all
select solt5 from table1
union all
select solt6 from table1
union all
select solt7 from table1
union all
select solt8 from table1
union all
select solt9 from table1)a
where b.id=a.solt