MySQL多选,多个子句

我想要运行一个大查询,而不是为一个操作运行数百个SELECT查询,我希望这将减轻我服务器上的负载.

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,但即使这两个也无效.当我运行此代码时,我收到错误:

Operand should contain 1 column(s).

有什么建议?谢谢!

最佳答案
您可以尝试以下可能,但您可能需要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多选,多个子句 - 代码日志