Re: [SQL ] 請問要如何搜尋兩張資料表

看板Database作者 (雷)時間14年前 (2011/09/01 01:17), 編輯推噓0(003)
留言3則, 2人參與, 最新討論串3/3 (看更多)
很感謝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

09/01 03:10, , 1F
union all 會作sorting 所以那3~4秒有部份用在這吧
09/01 03:10, 1F

09/01 03:23, , 2F
另外你是用什資料庫? 還有id屬性有主鍵或索引嗎?
09/01 03:23, 2F

09/01 23:56, , 3F
我用的是mysql id有主鍵
09/01 23:56, 3F
文章代碼(AID): #1ENcot66 (Database)
文章代碼(AID): #1ENcot66 (Database)