#1248 - 每个派生表必须有自己的别名

时间:2013-01-12 05:24:24

标签: mysql select subquery alias

我正在运行此查询

SELECT *  
FROM (`T_INV_DTL`)  
LEFT JOIN 
 (
  SELECT GROUP_CONCAT(DISTINCT T_INV_INVESTIGATOR.Employee_id) AS Employee_id
  FROM T_INV_INVESTIGATOR
  GROUP BY  `T_INV_INVESTIGATOR`.`inv_dtl_id`
  ) ON  `T_INV_DTL`.`inv_dtl_id` =  `T_INV_INVESTIGATOR`.`inv_dtl_id`
JOIN  `T_INVESTIGATION` ON  `T_INV_DTL`.`inv_id` =  `T_INVESTIGATION`.`inv_id` 

并且它给出了这个错误:

#1248 - 每个派生表都必须有自己的别名

有什么问题?

2 个答案:

答案 0 :(得分:2)

您必须为子查询提供别名,

检查一下:

SELECT * 
FROM T_INV_DTL T  
LEFT JOIN ( SELECT inv_dtl_id , GROUP_CONCAT( DISTINCT Employee_id ) AS Employee_id 
            FROM T_INV_INVESTIGATOR 
            GROUP BY inv_dtl_id ) A ON T.inv_dtl_id = A.inv_dtl_id 
JOIN T_INVESTIGATION TI ON T.inv_id = TI.inv_id  

答案 1 :(得分:0)

当您编写子查询时,您必须为whlole

提供别名

如果您有多个查询,那么最好使用别名在选择列表中指定不同的名称以避免冲突