本文介绍了MySQL多重选择,多重where子句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我不想只为一个操作运行数百个SELECT查询,而只是运行一个大查询,希望这可以减轻服务器的负载.
Instead of running hundreds of SELECT queries for one operation, I want to just run one big query, which I'm hoping will ease the load on my server.
SELECT (
(SELECT link_type_id FROM connections WHERE (node_to_id = '0' AND node_from_id = '1') OR (node_from_id = '1' AND node_to_id = '0')),
(SELECT link_type_id FROM connections WHERE (node_to_id = '0' AND node_from_id = '2') OR (node_from_id = '2' AND node_to_id = '0'))
)
此查询中将有更多的SELECTS,但即使这两个都不起作用.当我运行此代码时,出现错误:
There will be many more SELECTS in this query, but even the two aren't working. When I run this code I get the error:
Operand should contain 1 column(s).
有什么建议吗?谢谢!
推荐答案
您可以尝试以下操作,但可能需要UNION
You can try below may be but you may need UNION
SELECT link_type_id FROM connections
WHERE (node_to_id = '0' AND node_from_id = '1')
OR (node_from_id = '1' AND node_to_id = '0')
UNION
SELECT link_type_id FROM connections
WHERE (node_to_id = '0' AND node_from_id = '2')
OR (node_from_id = '2' AND node_to_id = '0')
这篇关于MySQL多重选择,多重where子句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!