我有三个表:供应商,零件和类型.我需要加入所有这些,同时在三个表中区分具有相同名称的列(例如,"id").我想成功运行此查询:
CREATE VIEW Everything AS SELECT Suppliers.name as supplier, Parts.id, Parts.description, Types.typedesc as type FROM Suppliers JOIN (Parts JOIN Types ON Parts.type_id = Types.id) ON Suppliers.id = Parts.supplier_id;
我的DBMS(sqlite)抱怨"没有这样的列(Parts.id)".我想在JOIN完成后会忘记表名,但是我怎样才能引用id
属于表的列Parts
呢?
您的ANSI-92 JOIN语法不正确 - 使用:
CREATE VIEW Everything AS SELECT Suppliers.name as supplier, Parts.id, Parts.description, Types.typedesc as type FROM Suppliers JOIN Parts ON Suppliers.id = Parts.supplier_id JOIN Types ON Parts.type_id = Types.id