<?php

$SQL = "create view view_permitfacts as

          select permitfacts.*,
                 date_format(permitfact_created, '%c/%e/%Y %l:%i %p') as permitfact_created_verbose,
                 date_format(permitfact_changed, '%c/%e/%Y %l:%i %p') as permitfact_changed_verbose,
                 date_format(permitfact_entry_date, '%c/%e/%Y')       as permitfact_entry_date_verbose,
                 date_format(permitfact_permit_date, '%c/%e/%Y')      as permitfact_permit_date_verbose,
          
            counties.county_name                                      as permitfact_county_name_verbose,
            permitfactcity.city_name                                  as permitfact_city_verbose,
            projectcity.city_name                                     as project_city_verbose,
            ownercity.city_name                                       as owner_city_verbose,

            projecttypes.dropdown_value                               as permitfact_project_type_verbose,
            worktypes.dropdown_value                                  as permitfact_work_type_verbose,
            buildingtypes.dropdown_value                              as permitfact_building_type_verbose

            from permitfacts

       left join counties
              on counties.county_serial = permitfacts.permitfact_county
              
       left join cities as permitfactcity
              on permitfactcity.city_serial = permitfacts.permitfact_city
              
       left join cities as projectcity
              on projectcity.city_serial = permitfacts.permitfact_project_city
              
       left join cities as ownercity
              on ownercity.city_serial = permitfacts.permitfact_owner_city
        
        left join dropdowns as projecttypes
              on projecttypes.dropdown_serial = permitfacts.permitfact_project_type
              
        left join dropdowns as worktypes
              on worktypes.dropdown_serial = permitfacts.permitfact_work_type
              
        left join dropdowns as buildingtypes
              on buildingtypes.dropdown_serial = permitfacts.permitfact_building_type";
?>