Q:

Getting a #1054 - Unknown column' in 'on clause' when constructing a view when column exists.

I'm constructing a sql view with the following code:
create or replace view vw_fill_thresholds as
SELECT waypoint_loc.name,
material_typ.description as material, 
fill_thresholds.can_size,
fill_thresholds.threshold,
units.description as unit,
fill_thresholds.post_threshold_cost as ptc,
fill_thresholds.post_threshold_unit_id as ptu
FROM fill_thresholds, fill_locations, material_type, units, waypoint_locations
            left join `waypoint_locations` `waypoint_loc` on(`waypoint_locations`.`id` = `fill_locations`.`waypoint_id`)
            left join `material_type` `material_typ` on(`material_type`.`id` = `fill_locations`.`material`)

WHERE  fill_thresholds.fill_id = fill_locations.id
            and fill_locations.unit_id = units.unit_id
            and fill_thresholds.deleted = 0;

My first questions is: 
I don't know if I'm going in the right direction but basically what I want to do is to have fields from materials and wabpoints table using a foreign key that I have in the fill_locations table which is referenced by a key that I have in the fill_threshold table. 
and my second question is:
Why do I get an error "#1054 - Unknown column 'fill_locations.waypoint_id' in 'on clause' " when I execute that code if I know that waypoint_id exists in the fill_locations table?
Any help would be appreciated 

A:

FROM fill_thresholds
left join fill_locations on fill_thresholds.fill_id = fill_locations.id 
and fill_thresholds.deleted = 0
left join units on  fill_locations.unit_id = units.unit_id
left join waypoint_locations on `waypoint_locations`.`id` = `fill_locations`.`waypoint_id`
left join `material_type` on `material_type`.`id` = `fill_locations`.`material`

Change your from conditions to the above, which uses appropriate joins. Your query was incorrect syntax-wise. (table used twice)

