Mysql工作select语句作为视图失败

时间:2016-04-13 10:09:38

标签: mysql sql

我有这个select语句,它可以作为exprected

使用
select wp1.idTour as tour,null as Search,g1.id,g2.id from GeoDB g1,
GeoDB g2,Waypoint wp1 join Waypoint wp2 
where wp1.idTour = wp2.idTour and wp1.GeoDB_id=g1.id and wp2.GeoDB_id=g2.id 
union all 
select null as tour,idSearch as Search,PickupLocation,DeliveryLocation 
from  Search where AutoBid_id>0

现在与

完全相同
Create view Myview as select...

失败
ERROR 1060 (42S21): Duplicate column name 'id'

有什么想法吗?

1 个答案:

答案 0 :(得分:0)

在您的查询结果中,两列具有相同名称id,如下所示:

g1.id,g2.id

试试这个

SELECT wp1.idTour AS tour,NULL AS Search,g1.id PickupLocation,g2.id DeliveryLocation
FROM GeoDB g1,GeoDB g2,Waypoint wp1 JOIN Waypoint wp2 
WHERE wp1.idTour = wp2.idTour AND wp1.GeoDB_id = g1.id AND wp2.GeoDB_id = g2.id 
UNION ALL
SELECT NULL AS tour,idSearch AS Search, PickupLocation, DeliveryLocation 
FROM  Search 
WHERE AutoBid_id>0