# SQL Help \[SOLVED\]

**URL:** <https://forum.phpvms.net/t/sql-help-solved/4837>\
**Category:** phpVMS Legacy Support (v2/v5)\
**Created:** [June 8, 2011, 1:32pm UTC](https://forum.phpvms.net/t/sql-help-solved/4837 "2011-06-08T13:32:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mark1million](https://forum.phpvms.net/user_avatar/forum.phpvms.net/mark1million/32/15_2.png) [@mark1million](https://forum.phpvms.net/u/mark1million)\
**Post date:** [June 8, 2011, 1:32pm UTC](https://forum.phpvms.net/t/sql-help-solved/4837/1 "2011-06-08T13:32:39Z")

</div>

Hi,

I am writing a module to only display unique ICAO aircraft, this is what i have,

```
/**
    * Get an aircraft by unique name
    */
   public static function getAircraftByName1() {

       $sql = 'SELECT DISTINCT icao, fullname, weight, cruise, maxpax, maxcargo, imagelink, downloadlink
			FROM ' . TABLE_PREFIX . 'aircraft 
			WHERE `enabled` = 1 ';

       return DB::get_results($sql);
   }

```

That works fine, but when i try to add the range nothing is displayed so if i do,

```
/**
    * Get an aircraft by unique name
    */
   public static function getAircraftByName1() {

       $sql = 'SELECT DISTINCT icao, fullname, range, weight, cruise, maxpax, maxcargo, imagelink, downloadlink
			FROM ' . TABLE_PREFIX . 'aircraft 
			WHERE `enabled` = 1 ';

       return DB::get_results($sql);
   }

```

Not sure why but any help would be appreciated

Thanks.

---

<div class="post-metadata">

**Author:** ![nabeel](https://forum.phpvms.net/user_avatar/forum.phpvms.net/nabeel/32/2971_2.png) [@nabeel](https://forum.phpvms.net/u/nabeel)\
**Post date:** [June 8, 2011, 2:45pm UTC](https://forum.phpvms.net/t/sql-help-solved/4837/2 "2011-06-08T14:45:13Z")

</div>

A couple things:

```
DISTINCT icao, fullname, range, weight ...

```

That looks for ALL of those fields as DISTINCT, you’d want to do DISTINCT(icao).

Aside from that, you might be looking to use GROUP BY instead of DISTINCT

**edit:** nevermind on the GROUP BY

**edit:** I see the problem.

Enclose field names with `:

```
$sql = 'SELECT DISTINCT `icao`, `fullname`, `range`, `weight`, `cruise`, `maxpax`, `maxcargo`, `imagelink`, `downloadlink`
                               FROM `' . TABLE_PREFIX . 'aircraft` 
                               WHERE `enabled` = 1 ';

```

---

<div class="post-metadata">

**Author:** ![mark1million](https://forum.phpvms.net/user_avatar/forum.phpvms.net/mark1million/32/15_2.png) [@mark1million](https://forum.phpvms.net/u/mark1million)\
**Post date:** [June 8, 2011, 5:55pm UTC](https://forum.phpvms.net/t/sql-help-solved/4837/3 "2011-06-08T17:55:17Z")

</div>

Thanks Jeff and Nabeel for your help.
