I’m trying to run a query, that I will turn into a mySQL query from a from with multiple search options. Here’s the query I’m testing in 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
All of the OR statements will turn into ‘?’ in mySQL, so for now I’m using 100 which will only work with Store_num. So this should bring up a list of the employees who work at that store.
However, the error I’m getting says: #1060 – Duplicate column name ‘Mgr_ssn’
Here are my tables, not sure why they aren’t merging correctly.
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)
);
the problem is here
tables
EMPLOYEEandDEPARTMENThave bothMgr_ssncolumn. you need to specify the table in whichMgr_ssncome from, exan
aliaswould also help you solve it.so the full query would be
but this query will also work because you don’t
Mgr_ssncolumn