1

所以我正在尝试做一个有点复杂的查询并且遇到了麻烦。我将其结构如下,因为它似乎是最合乎逻辑的:

SELECT (intake.id, s_matters.id, s_calls.cid, s_events.id) AS id, 
      (intake.name, s_matters.casename, s_calls.name, s_events.subject) AS title 
 FROM intake, s_matters, s_calls, s_events 
WHERE title LIKE '%mi%'

返回:

错误代码:1241
操作数应包含 1 列

所以我知道它与括号结构有关,但我不知道如何正确地做到这一点。

4

3 回答 3

4

别名只能引用一列。如果别名用于每个列表中的最后一列,请执行以下操作:

SELECT intake.id, s_matters.id, s_calls.cid, s_events.id AS id, intake.name, 
    s_matters.casename, s_calls.name, s_events.subject AS title 
FROM intake, s_matters, s_calls, s_events 
WHERE title LIKE '%mi%' 

此外,您的连接中缺少ON子句。查询试图完成什么?

于 2010-09-13T19:37:33.487 回答
2

目前尚不清楚您要做什么

SELECT concat(intake.id, s_matters.id, s_calls.cid, s_events.id) AS id, concat(intake.name, s_matters.casename, s_calls.name, s_events.subject) AS title FROM 摄入量, s_matters, s_calls, s_events WHERE 标题 LIKE '%mi%

可能是你想要的。正如 redfilter 指出的那样,您的联接缺少 ON 子句。

于 2010-09-13T19:41:12.027 回答
0

我怀疑最好通过以下方式返回所需的内容:

SELECT id, name title, 'intake' table 
FROM intake WHERE name LIKE '%mi%'  
UNION ALL
SELECT id, casename title, 's_matters' table 
FROM s_matters WHERE casename LIKE '%mi%'  
UNION ALL
SELECT cid AS id, name title, 's_calls' table 
FROM s_calls WHERE name LIKE '%mi%'  
UNION ALL
SELECT id, subject title, 's_events' table 
FROM s_events WHERE subject LIKE '%mi%'
于 2010-09-14T14:16:09.617 回答