2

The object of my query is to search for a long string in a database. To speed up this process, all records of the longstring table have a hash of that string on the same record. I want to first find all records in the table where my search string's hash is equal to a hash on the longstring table. Then after I have that dataset, I want to compare the actual strings (since hashes aren't always unique).

Now in oracle or mssql I would do this...

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

... but mysql doesn't support 'with' clauses. So what is my best alternative in mysql?

Thanks in advance!

Shog9
  • 152,046
  • 34
  • 225
  • 232
Nate
  • 1,885
  • 7
  • 22
  • 33

2 Answers2

4

You can do it with a sub-select:

select *
from (
  select long_string
  from longstring
  where hash = 'searchhash'
) AS dataset
where long_string = 'searchstring'
True Soft
  • 8,506
  • 6
  • 51
  • 79
2

This is the same as an AND clause.

SELECT  *
FROm longstring
WHERE hash = 'searchhash'
AND long_string = 'searchstring'
Adriaan Stander
  • 156,697
  • 29
  • 278
  • 282