简体   繁体   English

创建视图,错误代码:1052。字段中的“ id”列不明确

[英]Creating a view, Error Code: 1052. Column “id” in field is ambiguous

I am trying to create a view, but it comes up with an error code of: 1052. 我正在尝试创建一个视图,但它带有错误代码:1052。

I understand the problem, because I have looked at a similar post to my. 我了解这个问题,因为我看过与我相似的帖子。 I have found out that I need alias in my query. 我发现我的查询中需要别名。

This is what I coded originally: 这是我最初编写的代码:

create view checkd as (select * from wms join outerb on wms.barcode = 
concat('0',outerb.barcode));

And this is my attempt I tried to code with alias: 这是我尝试使用别名进行编码的尝试:

create view checkd as (select wms.id as wms.idWMS, wms.pcode as 
wms.pcodeWMS, wms.barcode as barcodeWMS from wms join outerb on 
wms.barcodeWMS = concat('0',outerb.barcode));

can someone point me to the right direction? 有人可以指出我正确的方向吗? Where Im I going wrong? 我哪里错了?

Below are my columns with their types 以下是我的列及其类型

Table: outerb
Columns:
id int(11) AI PK 
pcode varchar(255) 
brand varchar(255) 
descr varchar(255) 
size varchar(255) 
barcode varchar(255) 
checkd varchar(255)

` `

Table: wms
Columns:
id int(11) AI PK 
pcode varchar(255) 
barcode varchar(255)

using MySQL workbench. 使用MySQL工作台。

You have a load of errors in your view try this 您的视图中有很多错误,请尝试以下操作

create view checkd as (select wms.id as wmsid, wms.pcode as 
wmspcodeWMS, wms.barcode as barcodeWMS from wms join outerb on 
wms.barcode = concat('0',outerb.barcode));

In first create view you have two id and using * the result is ambigous 在第一个创建视图中,您有两个id并使用*结果不明确
In the second create view try using a simple column name alias 在第二个创建视图中,尝试使用简单的列名别名

  create view checkd as (
    select wms.id as idWMS
      , wms.pcode as pcodeWMS
      , wms.barcode as barcodeWMS 
    from wms 
    join outerb on  wms.barcodeWMS = concat('0', outerb.barcode));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM