SELECT bgpvpns.project_id AS bgpvpns_project_id,
    bgpvpns.id AS bgpvpns_id,
    bgpvpns.name AS bgpvpns_name,
    bgpvpns.type AS bgpvpns_type,
    bgpvpns.route_targets AS bgpvpns_route_targets,
    bgpvpns.import_targets AS bgpvpns_import_targets,
    bgpvpns.export_targets AS bgpvpns_export_targets,
    bgpvpns.route_distinguishers AS bgpvpns_route_distinguishers,
    subnetpoolprefixes_1.cidr AS subnetpoolprefixes_1_cidr,
    subnetpoolprefixes_1.subnetpool_id AS subnetpoolprefixes_1_subnetpool_id,
    standardattributes_1.id AS standardattributes_1_id,
    standardattributes_1.resource_type AS standardattributes_1_resource_type,
    standardattributes_1.description AS standardattributes_1_description,
    standardattributes_1.revision_number AS standardattributes_1_revision_number,
    standardattributes_1.created_at AS standardattributes_1_created_at,
    standardattributes_1.updated_at AS standardattributes_1_updated_at,
    tags_1.standard_attr_id AS tags_1_standard_attr_id,
    tags_1.tag AS tags_1_tag,
    subnetpools_1.project_id AS subnetpools_1_project_id,
    subnetpools_1.id AS subnetpools_1_id,
    subnetpools_1.name AS subnetpools_1_name,
    subnetpools_1.ip_version AS subnetpools_1_ip_version,
    subnetpools_1.default_prefixlen AS subnetpools_1_default_prefixlen,
    subnetpools_1.min_prefixlen AS subnetpools_1_min_prefixlen,
    subnetpools_1.max_prefixlen AS subnetpools_1_max_prefixlen,
    subnetpools_1.shared AS subnetpools_1_shared,
    subnetpools_1.is_default AS subnetpools_1_is_default,
    subnetpools_1.default_quota AS subnetpools_1_default_quota,
    subnetpools_1.hash AS subnetpools_1_hash,
    subnetpools_1.address_scope_id AS subnetpools_1_address_scope_id,
    subnetpools_1.standard_attr_id AS subnetpools_1_standard_attr_id,
    ipallocationpools_1.id AS ipallocationpools_1_id,
    ipallocationpools_1.subnet_id AS ipallocationpools_1_subnet_id,
    ipallocationpools_1.first_ip AS ipallocationpools_1_first_ip,
    ipallocationpools_1.last_ip AS ipallocationpools_1_last_ip,
    dnsnameservers_1.address AS dnsnameservers_1_address,
    dnsnameservers_1.subnet_id AS dnsnameservers_1_subnet_id,
    dnsnameservers_1.`order` AS dnsnameservers_1_order,
    subnetroutes_1.destination AS subnetroutes_1_destination,
    subnetroutes_1.nexthop AS subnetroutes_1_nexthop,
    subnetroutes_1.subnet_id AS subnetroutes_1_subnet_id,
    networkrbacs_1.project_id AS networkrbacs_1_project_id,
    networkrbacs_1.id AS networkrbacs_1_id,
    networkrbacs_1.target_tenant AS networkrbacs_1_target_tenant,
    networkrbacs_1.action AS networkrbacs_1_action,
    networkrbacs_1.object_id AS networkrbacs_1_object_id,
    standardattributes_2.id AS standardattributes_2_id,
    standardattributes_2.resource_type AS standardattributes_2_resource_type,
    standardattributes_2.description AS standardattributes_2_description,
    standardattributes_2.revision_number AS standardattributes_2_revision_number,
    standardattributes_2.created_at AS standardattributes_2_created_at,
    standardattributes_2.updated_at AS standardattributes_2_updated_at,
    tags_2.standard_attr_id AS tags_2_standard_attr_id,
    tags_2.tag AS tags_2_tag,
    subnets_1.project_id AS subnets_1_project_id,
    subnets_1.id AS subnets_1_id,
    subnets_1.name AS subnets_1_name,
    subnets_1.network_id AS subnets_1_network_id,
    subnets_1.segment_id AS subnets_1_segment_id,
    subnets_1.subnetpool_id AS subnets_1_subnetpool_id,
    subnets_1.ip_version AS subnets_1_ip_version,
    subnets_1.cidr AS subnets_1_cidr,
    subnets_1.gateway_ip AS subnets_1_gateway_ip,
    subnets_1.enable_dhcp AS subnets_1_enable_dhcp,
    subnets_1.ipv6_ra_mode AS subnets_1_ipv6_ra_mode,
    subnets_1.ipv6_address_mode AS subnets_1_ipv6_address_mode,
    subnets_1.standard_attr_id AS subnets_1_standard_attr_id,
    subnet_service_types_1.subnet_id AS subnet_service_types_1_subnet_id,
    subnet_service_types_1.service_type AS subnet_service_types_1_service_type,
    networkrbacs_2.project_id AS networkrbacs_2_project_id,
    networkrbacs_2.id AS networkrbacs_2_id,
    networkrbacs_2.target_tenant AS networkrbacs_2_target_tenant,
    networkrbacs_2.action AS networkrbacs_2_action,
    networkrbacs_2.object_id AS networkrbacs_2_object_id,
    agents_1.id AS agents_1_id,
    agents_1.agent_type AS agents_1_agent_type,
    agents_1.`binary` AS agents_1_binary,
    agents_1.topic AS agents_1_topic,
    agents_1.host AS agents_1_host,
    agents_1.availability_zone AS agents_1_availability_zone,
    agents_1.admin_state_up AS agents_1_admin_state_up,
    agents_1.created_at AS agents_1_created_at,
    agents_1.started_at AS agents_1_started_at,
    agents_1.heartbeat_timestamp AS agents_1_heartbeat_timestamp,
    agents_1.description AS agents_1_description,
    agents_1.configurations AS agents_1_configurations,
    agents_1.resource_versions AS agents_1_resource_versions,
    agents_1.`load` AS agents_1_load,
    standardattributes_3.id AS standardattributes_3_id,
    standardattributes_3.resource_type AS standardattributes_3_resource_type,
    standardattributes_3.description AS standardattributes_3_description,
    standardattributes_3.revision_number AS standardattributes_3_revision_number,
    standardattributes_3.created_at AS standardattributes_3_created_at,
    standardattributes_3.updated_at AS standardattributes_3_updated_at,
    tags_3.standard_attr_id AS tags_3_standard_attr_id,
    tags_3.tag AS tags_3_tag,
    networks_1.project_id AS networks_1_project_id,
    networks_1.id AS networks_1_id,
    networks_1.name AS networks_1_name,
    networks_1.status AS networks_1_status,
    networks_1.admin_state_up AS networks_1_admin_state_up,
    networks_1.vlan_transparent AS networks_1_vlan_transparent,
    networks_1.availability_zone_hints AS networks_1_availability_zone_hints,
    networks_1.standard_attr_id AS networks_1_standard_attr_id,
    qos_network_policy_bindings_1.policy_id AS qos_network_policy_bindings_1_policy_id,
    qos_network_policy_bindings_1.network_id AS qos_network_policy_bindings_1_network_id,
    externalnetworks_1.network_id AS externalnetworks_1_network_id,
    externalnetworks_1.is_default AS externalnetworks_1_is_default,
    networksecuritybindings_1.network_id AS networksecuritybindings_1_network_id,
    networksecuritybindings_1.port_security_enabled AS networksecuritybindings_1_port_security_enabled,
    networkdnsdomains_1.network_id AS networkdnsdomains_1_network_id,
    networkdnsdomains_1.dns_domain AS networkdnsdomains_1_dns_domain,
    bgpvpn_network_associations_1.id AS bgpvpn_network_associations_1_id,
    bgpvpn_network_associations_1.project_id AS bgpvpn_network_associations_1_project_id,
    bgpvpn_network_associations_1.bgpvpn_id AS bgpvpn_network_associations_1_bgpvpn_id,
    bgpvpn_network_associations_1.network_id AS bgpvpn_network_associations_1_network_id,
    ipallocations_1.port_id AS ipallocations_1_port_id,
    ipallocations_1.ip_address AS ipallocations_1_ip_address,
    ipallocations_1.subnet_id AS ipallocations_1_subnet_id,
    ipallocations_1.network_id AS ipallocations_1_network_id,
    standardattributes_4.id AS standardattributes_4_id,
    standardattributes_4.resource_type AS standardattributes_4_resource_type,
    standardattributes_4.description AS standardattributes_4_description,
    standardattributes_4.revision_number AS standardattributes_4_revision_number,
    standardattributes_4.created_at AS standardattributes_4_created_at,
    standardattributes_4.updated_at AS standardattributes_4_updated_at,
    tags_4.standard_attr_id AS tags_4_standard_attr_id,
    tags_4.tag AS tags_4_tag,
    ports_1.project_id AS ports_1_project_id,
    ports_1.id AS ports_1_id,
    ports_1.name AS ports_1_name,
    ports_1.network_id AS ports_1_network_id,
    ports_1.mac_address AS ports_1_mac_address,
    ports_1.admin_state_up AS ports_1_admin_state_up,
    ports_1.status AS ports_1_status,
    ports_1.device_id AS ports_1_device_id,
    ports_1.device_owner AS ports_1_device_owner,
    ports_1.ip_allocation AS ports_1_ip_allocation,
    ports_1.standard_attr_id AS ports_1_standard_attr_id,
    ml2_port_bindings_1.port_id AS ml2_port_bindings_1_port_id,
    ml2_port_bindings_1.host AS ml2_port_bindings_1_host,
    ml2_port_bindings_1.vnic_type AS ml2_port_bindings_1_vnic_type,
    ml2_port_bindings_1.profile AS ml2_port_bindings_1_profile,
    ml2_port_bindings_1.vif_type AS ml2_port_bindings_1_vif_type,
    ml2_port_bindings_1.vif_details AS ml2_port_bindings_1_vif_details,
    portsecuritybindings_1.port_id AS portsecuritybindings_1_port_id,
    portsecuritybindings_1.port_security_enabled AS portsecuritybindings_1_port_security_enabled,
    ml2_distributed_port_bindings_1.port_id AS ml2_distributed_port_bindings_1_port_id,
    ml2_distributed_port_bindings_1.host AS ml2_distributed_port_bindings_1_host,
    ml2_distributed_port_bindings_1.router_id AS ml2_distributed_port_bindings_1_router_id,
    ml2_distributed_port_bindings_1.vif_type AS ml2_distributed_port_bindings_1_vif_type,
    ml2_distributed_port_bindings_1.vif_details AS ml2_distributed_port_bindings_1_vif_details,
    ml2_distributed_port_bindings_1.vnic_type AS ml2_distributed_port_bindings_1_vnic_type,
    ml2_distributed_port_bindings_1.profile AS ml2_distributed_port_bindings_1_profile,
    ml2_distributed_port_bindings_1.status AS ml2_distributed_port_bindings_1_status,
    allowedaddresspairs_1.port_id AS allowedaddresspairs_1_port_id,
    allowedaddresspairs_1.mac_address AS allowedaddresspairs_1_mac_address,
    allowedaddresspairs_1.ip_address AS allowedaddresspairs_1_ip_address,
    securitygroupportbindings_1.port_id AS securitygroupportbindings_1_port_id,
    securitygroupportbindings_1.security_group_id AS securitygroupportbindings_1_security_group_id,
    subports_1.port_id AS subports_1_port_id,
    subports_1.trunk_id AS subports_1_trunk_id,
    subports_1.segmentation_type AS subports_1_segmentation_type,
    subports_1.segmentation_id AS subports_1_segmentation_id,
    extradhcpopts_1.id AS extradhcpopts_1_id,
    extradhcpopts_1.port_id AS extradhcpopts_1_port_id,
    extradhcpopts_1.opt_name AS extradhcpopts_1_opt_name,
    extradhcpopts_1.opt_value AS extradhcpopts_1_opt_value,
    extradhcpopts_1.ip_version AS extradhcpopts_1_ip_version,
    subports_2.port_id AS subports_2_port_id,
    subports_2.trunk_id AS subports_2_trunk_id,
    subports_2.segmentation_type AS subports_2_segmentation_type,
    subports_2.segmentation_id AS subports_2_segmentation_id,
    standardattributes_5.id AS standardattributes_5_id,
    standardattributes_5.resource_type AS standardattributes_5_resource_type,
    standardattributes_5.description AS standardattributes_5_description,
    standardattributes_5.revision_number AS standardattributes_5_revision_number,
    standardattributes_5.created_at AS standardattributes_5_created_at,
    standardattributes_5.updated_at AS standardattributes_5_updated_at,
    tags_5.standard_attr_id AS tags_5_standard_attr_id,
    tags_5.tag AS tags_5_tag,
    trunks_1.project_id AS trunks_1_project_id,
    trunks_1.id AS trunks_1_id,
    trunks_1.admin_state_up AS trunks_1_admin_state_up,
    trunks_1.name AS trunks_1_name,
    trunks_1.port_id AS trunks_1_port_id,
    trunks_1.status AS trunks_1_status,
    trunks_1.standard_attr_id AS trunks_1_standard_attr_id,
    qos_port_policy_bindings_1.policy_id AS qos_port_policy_bindings_1_policy_id,
    qos_port_policy_bindings_1.port_id AS qos_port_policy_bindings_1_port_id,
    portdnses_1.port_id AS portdnses_1_port_id,
    portdnses_1.current_dns_name AS portdnses_1_current_dns_name,
    portdnses_1.current_dns_domain AS portdnses_1_current_dns_domain,
    portdnses_1.previous_dns_name AS portdnses_1_previous_dns_name,
    portdnses_1.previous_dns_domain AS portdnses_1_previous_dns_domain,
    portdnses_1.dns_name AS portdnses_1_dns_name,
    agents_2.id AS agents_2_id,
    agents_2.agent_type AS agents_2_agent_type,
    agents_2.`binary` AS agents_2_binary,
    agents_2.topic AS agents_2_topic,
    agents_2.host AS agents_2_host,
    agents_2.availability_zone AS agents_2_availability_zone,
    agents_2.admin_state_up AS agents_2_admin_state_up,
    agents_2.created_at AS agents_2_created_at,
    agents_2.started_at AS agents_2_started_at,
    agents_2.heartbeat_timestamp AS agents_2_heartbeat_timestamp,
    agents_2.description AS agents_2_description,
    agents_2.configurations AS agents_2_configurations,
    agents_2.resource_versions AS agents_2_resource_versions,
    agents_2.`load` AS agents_2_load,
    standardattributes_6.id AS standardattributes_6_id,
    standardattributes_6.resource_type AS standardattributes_6_resource_type,
    standardattributes_6.description AS standardattributes_6_description,
    standardattributes_6.revision_number AS standardattributes_6_revision_number,
    standardattributes_6.created_at AS standardattributes_6_created_at,
    standardattributes_6.updated_at AS standardattributes_6_updated_at,
    tags_6.standard_attr_id AS tags_6_standard_attr_id,
    tags_6.tag AS tags_6_tag,
    routers_1.project_id AS routers_1_project_id,
    routers_1.id AS routers_1_id,
    routers_1.name AS routers_1_name,
    routers_1.status AS routers_1_status,
    routers_1.admin_state_up AS routers_1_admin_state_up,
    routers_1.gw_port_id AS routers_1_gw_port_id,
    routers_1.flavor_id AS routers_1_flavor_id,
    routers_1.standard_attr_id AS routers_1_standard_attr_id,
    router_extra_attributes_1.router_id AS router_extra_attributes_1_router_id,
    router_extra_attributes_1.distributed AS router_extra_attributes_1_distributed,
    router_extra_attributes_1.service_router AS router_extra_attributes_1_service_router,
    router_extra_attributes_1.ha AS router_extra_attributes_1_ha,
    router_extra_attributes_1.ha_vr_id AS router_extra_attributes_1_ha_vr_id,
    router_extra_attributes_1.availability_zone_hints AS router_extra_attributes_1_availability_zone_hints,
    routers_1.enable_snat AS routers_1_enable_snat,
    routerroutes_1.destination AS routerroutes_1_destination,
    routerroutes_1.nexthop AS routerroutes_1_nexthop,
    routerroutes_1.router_id AS routerroutes_1_router_id,
    bgpvpn_router_associations_1.id AS bgpvpn_router_associations_1_id,
    bgpvpn_router_associations_1.project_id AS bgpvpn_router_associations_1_project_id,
    bgpvpn_router_associations_1.bgpvpn_id AS bgpvpn_router_associations_1_bgpvpn_id,
    bgpvpn_router_associations_1.router_id AS bgpvpn_router_associations_1_router_id 
FROM bgpvpns
    LEFT OUTER JOIN bgpvpn_network_associations AS bgpvpn_network_associations_1 ON bgpvpns.id = bgpvpn_network_associations_1.bgpvpn_id
    LEFT OUTER JOIN networks AS networks_1 ON networks_1.id = bgpvpn_network_associations_1.network_id
    LEFT OUTER JOIN subnets AS subnets_1 ON networks_1.id = subnets_1.network_id
    LEFT OUTER JOIN subnetpools AS subnetpools_1 ON subnets_1.subnetpool_id = subnetpools_1.id
    LEFT OUTER JOIN subnetpoolprefixes AS subnetpoolprefixes_1 ON subnetpools_1.id = subnetpoolprefixes_1.subnetpool_id
    LEFT OUTER JOIN standardattributes AS standardattributes_1 ON standardattributes_1.id = subnetpools_1.standard_attr_id
    LEFT OUTER JOIN tags AS tags_1 ON standardattributes_1.id = tags_1.standard_attr_id
    LEFT OUTER JOIN ipallocationpools AS ipallocationpools_1 ON subnets_1.id = ipallocationpools_1.subnet_id
    LEFT OUTER JOIN dnsnameservers AS dnsnameservers_1 ON subnets_1.id = dnsnameservers_1.subnet_id
    LEFT OUTER JOIN subnetroutes AS subnetroutes_1 ON subnets_1.id = subnetroutes_1.subnet_id
    LEFT OUTER JOIN networkrbacs AS networkrbacs_1 ON subnets_1.network_id = networkrbacs_1.object_id
    LEFT OUTER JOIN standardattributes AS standardattributes_2 ON standardattributes_2.id = subnets_1.standard_attr_id
    LEFT OUTER JOIN tags AS tags_2 ON standardattributes_2.id = tags_2.standard_attr_id
    LEFT OUTER JOIN subnet_service_types AS subnet_service_types_1 ON subnets_1.id = subnet_service_types_1.subnet_id
    LEFT OUTER JOIN networkrbacs AS networkrbacs_2 ON networks_1.id = networkrbacs_2.object_id
    LEFT OUTER JOIN (networkdhcpagentbindings AS networkdhcpagentbindings_1 INNER JOIN agents AS agents_1 ON agents_1.id = networkdhcpagentbindings_1.dhcp_agent_id) ON networks_1.id = networkdhcpagentbindings_1.network_id
    LEFT OUTER JOIN standardattributes AS standardattributes_3 ON standardattributes_3.id = networks_1.standard_attr_id
    LEFT OUTER JOIN tags AS tags_3 ON standardattributes_3.id = tags_3.standard_attr_id
    LEFT OUTER JOIN qos_network_policy_bindings AS qos_network_policy_bindings_1 ON networks_1.id = qos_network_policy_bindings_1.network_id
    LEFT OUTER JOIN externalnetworks AS externalnetworks_1 ON networks_1.id = externalnetworks_1.network_id
    LEFT OUTER JOIN networksecuritybindings AS networksecuritybindings_1 ON networks_1.id = networksecuritybindings_1.network_id
    LEFT OUTER JOIN networkdnsdomains AS networkdnsdomains_1 ON networks_1.id = networkdnsdomains_1.network_id
    LEFT OUTER JOIN bgpvpn_router_associations AS bgpvpn_router_associations_1 ON bgpvpns.id = bgpvpn_router_associations_1.bgpvpn_id
    LEFT OUTER JOIN routers AS routers_1 ON routers_1.id = bgpvpn_router_associations_1.router_id
    LEFT OUTER JOIN ports AS ports_1 ON ports_1.id = routers_1.gw_port_id
    LEFT OUTER JOIN ipallocations AS ipallocations_1 ON ports_1.id = ipallocations_1.port_id
    LEFT OUTER JOIN standardattributes AS standardattributes_4 ON standardattributes_4.id = ports_1.standard_attr_id
    LEFT OUTER JOIN tags AS tags_4 ON standardattributes_4.id = tags_4.standard_attr_id
    LEFT OUTER JOIN ml2_port_bindings AS ml2_port_bindings_1 ON ports_1.id = ml2_port_bindings_1.port_id
    LEFT OUTER JOIN portsecuritybindings AS portsecuritybindings_1 ON ports_1.id = portsecuritybindings_1.port_id
    LEFT OUTER JOIN ml2_distributed_port_bindings AS ml2_distributed_port_bindings_1 ON ports_1.id = ml2_distributed_port_bindings_1.port_id
    LEFT OUTER JOIN allowedaddresspairs AS allowedaddresspairs_1 ON ports_1.id = allowedaddresspairs_1.port_id
    LEFT OUTER JOIN securitygroupportbindings AS securitygroupportbindings_1 ON ports_1.id = securitygroupportbindings_1.port_id
    LEFT OUTER JOIN subports AS subports_1 ON ports_1.id = subports_1.port_id
    LEFT OUTER JOIN extradhcpopts AS extradhcpopts_1 ON ports_1.id = extradhcpopts_1.port_id
    LEFT OUTER JOIN trunks AS trunks_1 ON ports_1.id = trunks_1.port_id
    LEFT OUTER JOIN subports AS subports_2 ON trunks_1.id = subports_2.trunk_id
    LEFT OUTER JOIN standardattributes AS standardattributes_5 ON standardattributes_5.id = trunks_1.standard_attr_id
    LEFT OUTER JOIN tags AS tags_5 ON standardattributes_5.id = tags_5.standard_attr_id
    LEFT OUTER JOIN qos_port_policy_bindings AS qos_port_policy_bindings_1 ON ports_1.id = qos_port_policy_bindings_1.port_id
    LEFT OUTER JOIN portdnses AS portdnses_1 ON ports_1.id = portdnses_1.port_id
    LEFT OUTER JOIN (routerl3agentbindings AS routerl3agentbindings_1 INNER JOIN agents AS agents_2 ON agents_2.id = routerl3agentbindings_1.l3_agent_id) ON routers_1.id = routerl3agentbindings_1.router_id
    LEFT OUTER JOIN standardattributes AS standardattributes_6 ON standardattributes_6.id = routers_1.standard_attr_id
    LEFT OUTER JOIN tags AS tags_6 ON standardattributes_6.id = tags_6.standard_attr_id
    LEFT OUTER JOIN router_extra_attributes AS router_extra_attributes_1 ON routers_1.id = router_extra_attributes_1.router_id
    LEFT OUTER JOIN routerroutes AS routerroutes_1 ON routers_1.id = routerroutes_1.router_id 
ORDER BY dnsnameservers_1.`order`