作者phreat (雷)
看板Database
标题Re: [SQL ] 请问要如何搜寻两张资料表
时间Thu Sep 1 01:17:41 2011
很感谢chunhsiang 的解惑
刚测试过可行,但遇有个小小问题是两张10万笔的资料做此动作大概需要跑3-4秒
所以最後改写成
select a.id as id, a.enable as enable
from a
where a.enable is not null
输出成阵列 a_arry
select b.id, b.enable
from b
where b.enable is not null
输出成阵列 b_arry
在将两阵列合并
※ 引述《chunhsiang (= =)》之铭言:
: ※ 引述《phreat (雷)》之铭言:
: : 请问一下
: : 以下为两张表
: : table a
: : id enable
: : 1
: : 2 1
: : 3 1
: : 4 1
: : table b
: : id enable
: : 4 1
: : 5 1
: : 6 1
: : 请问有办法印出
: : id enable
: : 2 1
: : 3 1
: : 4 1
: : 4 1
: : 5 1
: : 6 1
: : 测试过FULL JOIN , UNION 等都无法达成如果使用
: : select * from a as a ,b as b
: : 会变成
: : id enable id enable
: : ....
: : ....
: : ....
: : ....
: select a.id as id, a.enable as enable
: from a
: where a.enable is not null
: union all
: select b.id, b.enable
: from b
: where b.enable is not null
: ;
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 112.105.189.66
1F:→ chunhsiang:union all 会作sorting 所以那3~4秒有部份用在这吧 09/01 03:10
2F:→ chunhsiang:另外你是用什资料库? 还有id属性有主键或索引吗? 09/01 03:23
3F:→ phreat:我用的是mysql id有主键 09/01 23:56