我正在尝试运行一个查询,我将从具有多个搜索选项的 from 转换为 mySQL 查询。这是我在 myPHPadmin 中测试的查询
SELECT Fname, Minit, Lname, Address, Hourly, Sname, Saddress, Dno
FROM (SELECT *
FROM EMPLOYEE, DEPARTMENT, LOCATION
WHERE EMPLOYEE.Dno = DEPARTMENT.Dnumber AND
LOCATION.Store_num = DEPARTMENT.Store_num AND
(Fname='100' OR Lname='100'
OR LOCATION.Store_num ='100' OR Dno='100')) X
所有的 OR 语句都将变成 '?' 在 mySQL 中,所以现在我使用 100,它只适用于 Store_num。因此,这应该会列出在该商店工作的员工名单。
但是,我得到的错误是:#1060 - Duplicate column name 'Mgr_ssn'
这是我的表,不知道为什么它们没有正确合并。
CREATE TABLE EMPLOYEE
( Fname VARCHAR(15) not null,
Minit CHAR,
Lname VARCHAR(15) not null,
Ssn CHAR(9) not null,
Bdate DATE,
Address VARCHAR(30),
Hourly DECIMAL(5,2),
Mgr_ssn CHAR(9),
Dno INT not null,
Start_date DATE,
Phone CHAR(10),
PRIMARY KEY (Ssn),
FOREIGN KEY (Mgr_ssn) REFERENCES EMPLOYEE(Ssn),
FOREIGN KEY (Dno) REFERENCES DEPARTMENT(Dnumber) );
CREATE TABLE DEPARTMENT
( Dname VARCHAR(15) not null,
Dnumber INT not null,
Mgr_ssn CHAR(9) not null,
Mgr_start_date DATE,
Phone CHAR(10),
Store_num INT not null,
PRIMARY KEY (Dnumber, Store_num),
UNIQUE (Dname),
FOREIGN KEY (Mgr_ssn) REFERENCES EMPLOYEE(Ssn),
FOREIGN KEY (Store_num) REFERENCES LOCATION(Store_num)
);
CREATE TABLE LOCATION
( Store_num INT NOT NULL,
Sname VARCHAR(15) NOT NULL,
Saddress VARCHAR(30) NOT NULL,
PRIMARY KEY (Store_num),
UNIQUE (Saddress)
);