看板 Database 關於我們 聯絡資訊
我的user是一個table , 紀錄使用者的上站紀錄. 主要的schema如下 sid int(11) auto_increment userId varchar(20) fromaddress varchar(60) 目前總資料筆數 62,835 ──────────────────────────────── 現在碰到的瓶頸是當我想找出與特定使用者(以下代稱xxx)時來源相同的使用者時, 我採用如底下所述的 sql 疑似會碰上搜尋瓶頸. (電腦會沒有回應 , 目前尚未找出確實原因, 執行環境是phpmyadmin for mysql , OS是 winxp .) SELECT u1.* FROM `user` u1 where u1.fromaddress in( select distinct u2.fromaddress from user u2 where u2.userid='xxx' ) ──────────────────────────────── 而我如果是作兩段式查詢 先作 select distinct u2.fromaddress from user u2 where u2.userid='xxx' 假設查到 'addr1' , 'addr2' 再把結果的字串手動寫到 SELECT u1.* FROM `user` u1 where u1.fromaddress in( 'addr1' , 'addr2' ) 這樣就還蠻順利的,想問問看我原本的寫法 , 是不是有造成笛卡爾乘績的疑慮,還是有什麼狀況. 因為in這個keyword不是個很好google的詞 , 所以上來請教~~ --;;; -- I am a person, and I am always thinking . Thinking in love , Thinking in life , Thinking in why , Thinking in worth. I can't believe any of what , I am just thinking then thinking , but worst of all , most of mine is thinking not actioning... -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 220.134.27.68
rosemary:第一個查詢的第二個user要不要加上引號試試看? 07/05 10:41