Index: includes/database/select.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/database/select.inc,v
retrieving revision 1.4
diff -u -p -r1.4 select.inc
--- includes/database/select.inc	15 Sep 2008 05:00:48 -0000	1.4
+++ includes/database/select.inc	6 Oct 2008 01:27:03 -0000
@@ -335,10 +335,17 @@ class SelectQuery extends Query implemen
    *   The unique alias that was assigned for this field.
    */
   public function addField($table_alias, $field, $alias = NULL) {
+    // If no alias is specified, first try the field name itself.
     if (empty($alias)) {
+      $alias = $field;
+    }
+
+    // If that's already in use, try the table name and field name.
+    if (!empty($this->tables[$alias])) {
       $alias = $table_alias . '_' . $field;
     }
 
+    // If that is already used, just add a counter until we find an unused alias.
     $alias_candidate = $alias;
     $count = 2;
     while (!empty($this->tables[$alias_candidate])) {
Index: modules/simpletest/tests/database_test.test
===================================================================
RCS file: /cvs/drupal/drupal/modules/simpletest/tests/database_test.test,v
retrieving revision 1.9
diff -u -p -r1.9 database_test.test
--- modules/simpletest/tests/database_test.test	28 Sep 2008 21:52:08 -0000	1.9
+++ modules/simpletest/tests/database_test.test	6 Oct 2008 01:27:04 -0000
@@ -983,7 +983,7 @@ class DatabaseSelectTestCase extends Dat
     $result = $query->execute();
 
     // Check that the aliases are being created the way we want.
-    $this->assertEqual($name_field, 'test_name', t('Name field alias is correct.'));
+    $this->assertEqual($name_field, 'name', t('Name field alias is correct.'));
     $this->assertEqual($age_field, 'age', t('Age field alias is correct.'));
 
     // Ensure that we got the right record.
@@ -1003,7 +1003,7 @@ class DatabaseSelectTestCase extends Dat
     $result = $query->execute();
 
     // Check that the aliases are being created the way we want.
-    $this->assertEqual($name_field, 'test_name', t('Name field alias is correct.'));
+    $this->assertEqual($name_field, 'name', t('Name field alias is correct.'));
     $this->assertEqual($age_field, 'double_age', t('Age field alias is correct.'));
 
     // Ensure that we got the right record.
