0

i want to write small select something like this

select t.id,func(t.name) from table t where func(t.name)>0

but i want to call function func only once

Can anybody help me?

javagc
  • 133
  • 6
  • 13
  • You can create your function as DETERMINISTIC which should allow MySQL to cache the results. – andy Sep 20 '14 at 19:07
  • The optimizer will eliminate common subexpressions. Just because you write a function twice does not mean it will be called twice. – gexicide Sep 20 '14 at 19:08

1 Answers1

0

Use HAVING:

SELECT t.id, func(t.name) AS f
FROM Table AS t
HAVING f > 0
Barmar
  • 741,623
  • 53
  • 500
  • 612