MySQL中的错误1248:“每个派生表必须有自己的别名”

时间:2013-10-10 11:19:28

标签: mysql

我正在尝试运行此查询:

SELECT DISTINCT col1 
FROM 
  (
   SELECT CONCAT(retailerId,'_recharge') FROM retailerinformation
   WHERE Channel='videocon' AND retailerId='kioskpb20130909045617'
  )

但每次运行时我都会收到此错误:

Error Code : 1248 Every derived table must have its own alias

4 个答案:

答案 0 :(得分:3)

你的错误很清楚。创建别名:

SELECT DISTINCT 
  col1 
FROM 
  (select concat(retailerId,'_recharge') from retailerinformation where Channel='videocon' and retailerId='kioskpb20130909045617') AS tmp_table

提示:如果您尝试了解错误,而不仅仅是阅读它们 - 这将是成功案例。

答案 1 :(得分:0)

试试这个版本:

select DISTINCT col1 from 
 (select concat(retailerId,'_recharge') from retailerinformation
   where Channel='videocon' and retailerId='kioskpb20130909045617') as retailerino

注意子查询上的别名。

答案 2 :(得分:0)

这将有效:

SELECT 
DISTINCT col1
FROM (
   SELECT concat(retailerId,'_recharge') 
   FROM retailerinformation where Channel='videocon' and retailerId='kioskpb20130909045617'
   ) AS alias

答案 3 :(得分:0)

除了在子查询中添加别名外,在外部查询中调用的列应该存在于子查询中。在这种情况下,col1应该存在于子查询中。话虽如此,这应该工作

SELECT DISTINCT col1 
FROM 
  (
   SELECT CONCAT(retailerId,'_recharge') col1 FROM retailerinformation
   WHERE Channel='videocon' AND retailerId='kioskpb20130909045617'
  ) sub