请问sql dilettante,谁能告诉我这个sql是否有效?

时间:2012-10-24 10:45:27

标签: mysql sql

我正在写一个像这样的SQL

SELECT uid
  FROM search
 WHERE MATCH(product) AGAINST('football basketball')
   AND status=1
 ORDER BY MATCH(product) AGAINST('football basketball') DESC

我在mysql中运行正常,但我不确定它是否有效。我想知道这个“ MATCH(产品)反对('足球篮球')”是否会跑两次?

2 个答案:

答案 0 :(得分:0)

这可能无需担心:

SELECT uid, MATCH(product) AGAINST('football basketball') as imatch
  FROM search
 WHERE imatch 
  AND status=1
 ORDER BY imatch DESC

答案 1 :(得分:0)

如果您不想同时选择匹配项,则需要将别名放在where子句中。但是别名只运行一次并将结果存储在“变量”

SELECT uid
FROM search
WHERE MATCH(product) AGAINST('football basketball') as imatch
AND status = 1
ORDER BY imatch DESC