I’m trying to use natural join to join two tables in mySQL that have a field that is equivalent, but named differently between the tables (I have to use natural join — I know it would be easier to use a different join). Natural join looks for fields with the same name, so I want to rename the column in one table to the same name as the one in the other table. In my textbook (not specific to mySQL) it says that the following should work:
SELECT Fname, Lname, Address
FROM (EMPLOYEE NATURAL JOIN
(DEPARTMENT AS DEPT (Dname, Dno, Mssn, Msdate)))
WHERE Dname=‘Research’;
The part that I’m interested in is the “DEPARTMENT AS DEPT (Dname, Dno, Mssn, Msdate)”… But I can’t replicate this in mySQL (it causes an error that says to check for the right syntax to use near ‘(Dname, Dno, Mssn, Msdate)’. Is there some way to (simply — without a nested SELECT/FROM query) rename individual columns like this in mySQL so that the natural join sees the columns as equivalent?
this is how you create an
ALIASin MySQL:for
FIELD(or columns) andTABLEresult: