简体   繁体   中英

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.

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.

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
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));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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