I am trying to execute this query to print data from three tables. But somehow the query is not being executed. 

```
SELECT l.locality_id, c.city_name, l.locality_name, cloud_site_location_outlet_localities.minimum_order, cloud_site_location_outlet_localities.delivery_time, cloud_site_location_outlet_localities.delivery_charge FROM `cloud_site_location_localities` l INNER JOIN `cloud_site_location_cities` c on l.city_id=c.city_id

```

The error that I get on executing above query is:

```
1054 - Unknown column 'cloud_site_location_outlet_localities.minimum_order' in 'field list'

```

However this query worked fine when I had to display data from two tables only. 

```
SELECT l.locality_id, c.city_name, l.locality_name FROM `cloud_site_location_localities` l INNER JOIN `cloud_site_location_cities` c on l.city_id=c.city_id

```

Where am I going wrong?

When I use the following query to export it in CSV, I get redundant data. Out of 1000 entries, I only get 400 and then those 400 are repeated. 

This is code I am implementing

```
$sql = "SELECT l.locality_id, c.city_name, l.locality_name, o.minimum_order, o.delivery_time, o.delivery_charge FROM `cloud_site_location_localities` l INNER JOIN `cloud_site_location_cities` c ON l.city_id = c.city_id INNER JOIN `cloud_site_location_outlet_localities` o ON l.locality_id = o.locality_id";
$result = $DB->query($sql);

//$output = fopen($filename, 'c+');
$output = fopen('php://output', 'c+');
fputcsv($output, array('Location Id', 'City Name', 'Location Name','Minimum Order Amount','Delivery Time','Delivery Charge'));
$row = array();
$csv_output = "";
$csv_output .= "Locality Id,City Name,Locality Name,Minimum Order Amount,Delivery Time,Delivery Charge\n";
foreach($result as $locality_value)
{
    $row['locality_id'] =   $locality_value->locality_id;
    $row['city_name']       =       $locality_value->city_name;
    $row['locality_name']   =   $locality_value->locality_name;
    $row['minimum_order']   =   $locality_value->minimum_order;
    $row['delivery_time']   =   $locality_value->delivery_time;
    $row['delivery_charge'] =   $locality_value->delivery_charge;
    $csv_output .= trim($row['locality_id']).",".trim($row['city_name']).",".trim($row['locality_name']).",".trim($row['minimum_order']).",".trim($row['delivery_time']).",".trim($row['delivery_charge']).",,\n";
    fputcsv($output, $row);

}
fclose($output);
print $csv_output;

```