看板 Database 關於我們 聯絡資訊
很感謝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
chunhsiang:union all 會作sorting 所以那3~4秒有部份用在這吧 09/01 03:10
chunhsiang:另外你是用什資料庫? 還有id屬性有主鍵或索引嗎? 09/01 03:23
phreat:我用的是mysql id有主鍵 09/01 23:56