子句中的mysql语法 [英] mysql syntax in clause

查看:81
本文介绍了子句中的mysql语法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用mysql,想知道它的语法.

im using mysql and was wondering about its syntax.

我想制作一个IN子句,像这样:

i want to make an IN clause something like this:

from_id OR to_id IN (
)

除了我不知道语法是什么

except i dont know how the syntax is

我想避免像这样两次运行in子句:

i want to avoid running the in clause twice like this:

from_id IN (
)

OR

to_id IN (
)

最好的问候 亚历山大

best of regards alexander

推荐答案

如果您出于某些原因担心IN子句运行两次(例如,如果子查询特别复杂并且优化器似乎没有)利用缓存结果集的优势),您始终可以将IN子句替换为INNER JOIN.

If you have some reasons to worry about the IN clause being run twice (for example, if the subquery is particularly complex and the optimiser doesn't seem to have taken advantage of caching the result set), you can always replace the IN clause with INNER JOIN.

所以这个:

FROM x
WHERE from_id IN (
  subquery
)
OR
to_id IN (
  subquery
)

成为这个:

FROM x
  INNER JOIN (
    subquery
  ) y ON y.value IN (x.from_id, x.to_id)

这篇关于子句中的mysql语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆