I have 3 tables. In table_1 and table_2 I have field called plevel. Third table is to join them and is.
cars_user and have 2 columns - table1_plevel and table2_plevel
The query that I want to select is
$q = mysqli_query($con, "SELECT * FROM `cars` AS c
LEFT JOIN `cars_user` AS c2u ON c.cars_plevel = c2u.car_plevel
LEFT JOIN `users` AS u ON c2u.user_plevel = u.users_plevel");
When I run it I get that the column is Unknown but I know that this column is there.
#1054 - Unknown column 'c.cars_plevel' in 'on clause'
I have put references also in cars_user to cars.plevel and users.plevel
ALTER TABLE `cars_user` ADD FOREIGN KEY ( `cars_plevel` )
REFERENCES `app`.`cars` (`plevel`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `cars_user` ADD FOREIGN KEY ( `user_plevel` )
REFERENCES `app`.`users` (`plevel`) ON DELETE RESTRICT ON UPDATE RESTRICT;
What is the problem here?