查询:
SELECT max(image_url), Model_Name
FROM (
SELECT max(image_url), Model_Name
FROM dbo.proinfo_vodafone WHERE Brand_name='Nokia'
UNION
SELECT max(image_url), Model_Name
FROM dbo.proinfo_3 WHERE Brand_name='Nokia'
UNION
SELECT max(image_url), Model_Name
FROM dbo.proinfo_t WHERE Brand_name='Nokia'
UNION
SELECT max(image_url), Model_Name
FROM dbo.proinfo_o2 WHERE Brand_name='Nokia'
UNION
SELECT max(image_url), Model_Name
FROM dbo.proinfo_orange
WHERE Brand_name='Nokia') AS temp
WHERE Model_Name IS NOT NULL
GROUP BY Model_Name
ORDER BY Model_name ASC
给出错误:Msg 8155,Level 16,State 2,Line 3 没有为'temp'的第1列指定列。
现在,说实话我不熟悉SQL,我在类似的查询中使用Quick Replace进行了这个查询,我似乎无法理解查询的错误。
请帮忙! 在此先感谢。
Anchit
答案 0 :(得分:5)
SELECT MAX(image_url), Model_Name
FROM (SELECT MAX(image_url) image_url, Model_Name
FROM dbo.proinfo_vodafone
WHERE Brand_name = 'Nokia'
UNION
SELECT MAX(image_url) image_url, Model_Name
FROM dbo.proinfo_3
WHERE Brand_name = 'Nokia'
UNION
SELECT MAX(image_url) image_url, Model_Name
FROM dbo.proinfo_t
WHERE Brand_name = 'Nokia'
UNION
SELECT MAX(image_url) image_url, Model_Name
FROM dbo.proinfo_o2
WHERE Brand_name = 'Nokia'
UNION
SELECT MAX(image_url) image_url, Model_Name
FROM dbo.proinfo_orange
WHERE Brand_name = 'Nokia') AS temp
WHERE Model_Name IS NOT NULL
GROUP BY Model_Name
ORDER BY Model_name ASC