Re: [SQL ] 選取特定主鍵跟其下一筆之外的資料

看板Database作者 (艾瑞克)時間17年前 (2008/06/25 17:02), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串2/7 (看更多)
※ 引述《JYHuang (夏天到了,冷不起來了說)》之銘言: : 感謝~ : 不過查詢結果似乎還是沒有排除 id=10 跟其下一筆 : 設原資料有 id 10,11,12三筆的話,欲查詢 id in(10,11)以外的 : 我們下的查詢都是顯示 : id ..... : 10 ... <-- right join : 11 ... <-- 合併進來的資料? @@ : 12 ... : 12 ... <-- select news.* from news, (select id from news where id=10 order by id limit 1 ) as a , (select id from news where id>10 order by id limit 1 ) as b where news.id<>a.id and news.id<>b.id order by news.id 但是我只能說 效能慘不睹:) 查詢前=>993 總計, 查詢需時 0.0095 秒 查詢後=>991 總計, 查詢需時 0.4377 秒 PS.記得把news改成你的tablename -- Best Regards, Arrack Tseng -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 59.126.63.16 ※ 編輯: arrack 來自: 59.126.63.16 (06/25 17:04) ※ 編輯: arrack 來自: 59.126.63.16 (06/25 17:05)
文章代碼(AID): #18OWcvx5 (Database)
討論串 (同標題文章)
文章代碼(AID): #18OWcvx5 (Database)