mySQL版本的';与';条款
我查询的对象是在数据库中搜索长字符串。为了加快此过程,在同一记录上,mySQL版本的';与';条款,mysql,with-clause,Mysql,With Clause,我查询的对象是在数据库中搜索长字符串。为了加快此过程,在同一记录上,longstring表的所有记录都有该字符串的散列。我想首先查找表中的所有记录,其中我的搜索字符串的哈希值等于longstring表中的哈希值。在获得数据集之后,我想比较实际的字符串(因为哈希并不总是唯一的) 现在在oracle或mssql中,我会这样做 with dataset as ( select long_string from longstring where hash = 'searchhash' ) s
longstring
表的所有记录都有该字符串的散列。我想首先查找表中的所有记录,其中我的搜索字符串的哈希值等于longstring
表中的哈希值。在获得数据集之后,我想比较实际的字符串(因为哈希并不总是唯一的)
现在在oracle或mssql中,我会这样做
with dataset as (
select long_string
from longstring
where hash = 'searchhash'
) select *
from dataset
where long_string = 'searchstring'
。。。但是mysql不支持with子句。那么,我在mysql中的最佳选择是什么
提前谢谢 您可以通过子选择来完成:
select *
from (
select long_string
from longstring
where hash = 'searchhash'
) AS dataset
where long_string = 'searchstring'
这与和子句相同
SELECT *
FROm longstring
WHERE hash = 'searchhash'
AND long_string = 'searchstring'
供参考: