所以我试图做一个有点复杂的查询并遇到麻烦。我已将其结构化,因为它似乎是最符合逻辑的:
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列
所以我知道它与支架结构有关,但我不知道如何正确地做到这一点。
答案 0 :(得分: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
子句。试图完成的查询是什么?
答案 1 :(得分: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 intake,s_matters, s_calls,s_events WHERE标题LIKE'%mi%
可能是你的意图。正如redfilter指出你的联接缺少ON条款。
答案 2 :(得分: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%'