Here is my MySQL Query that im trying to execute. it keeps failing with the error:
Unknown column ‘staff_tbl.mainrank’ in field list. how is this possible?
DROP TEMPORARY TABLE IF EXISTS `staff_tbl`;
CREATE TEMPORARY TABLE staff_tbl(childrank TEXT, mainrank TEXT);
INSERT INTO staff_tbl
SELECT permissions_inheritance.child, permissions_inheritance.parent
FROM permissions_inheritance;
SELECT authme.username, permissions_inheritance.child,
permissions_inheritance.parent, staff_tbl.mainrank
FROM authme
INNER JOIN permissions_inheritance ON authme.username = permissions_inheritance.child
INNER JOIN staff_tbl alies2 ON staff_tbl.mainrank = permissions_inheritance.parent;
DROP TABLE `staff_tbl`;
I would greatly appreciate if you could help me. i have pulled every bit of my hair out. so you guys are my last hope. Im still a novice 🙂
In the last
SELECTyou have the last join wrong. You make a join withstaff_tbland give it an alias (alies2). You must use that alias in the statement that follows (alies2.mainrank = permissions_inheritance.parentinstead ofstaff_tbl.mainrank = permissions_inheritance.parent), you didn’t.Try writing your last
SELECTlike this:I fixed this above. I also set an alias for each table to make the query shorter and therefore more readable.