2009-12-14 162 views
2

我的查詢的對象是在數據庫中搜索長字符串。爲加速此過程,longstring表的所有記錄在同一記錄上都有該字符串的散列。我想先查找表中的所有記錄,其中我的搜索字符串的哈希值等於longstring表中的哈希值。然後,我有這個數據集後,我想比較實際的字符串(因爲散列並不總是唯一的)。'with'子句的mySQL版本

現在,Oracle或MSSQL我會做到這一點...

with dataset as (
    select long_string 
    from longstring 
    where hash = 'searchhash' 
) select * 
from dataset 
where long_string = 'searchstring' 

...但MySQL不 '與' 條款的支持。那麼在mysql中我最好的選擇是什麼?

在此先感謝!

+0

僅供參考:http://stackoverflow.com/questions/1382573/how-do-you-use-the-with-clause-in-mysql – 2009-12-14 19:37:01

回答

4

您可以用子選擇做到這一點:

select * 
from (
    select long_string 
    from longstring 
    where hash = 'searchhash' 
) AS dataset 
where long_string = 'searchstring' 
+0

..那叫一個愚蠢的問題,這是!謝謝 – Nate 2009-12-14 19:36:55

2

這是一樣的條款。

SELECT * 
FROm longstring 
WHERE hash = 'searchhash' 
AND long_string = 'searchstring'