Bug #6689 Order by an existing field does not work. Same query works in 4.0.18
Submitted: 17 Nov 2004 21:03 Modified: 26 Nov 2004 16:13
Reporter: al jones Email Updates:
Status: Duplicate Impact on me:
None 
Category:MySQL Server Severity:S1 (Critical)
Version:4.0.22 OS:Linux (fedora core 2)
Assigned to: Assigned Account CPU Architecture:Any

[17 Nov 2004 21:03] al jones
Description:
mysql> desc customfieldvalue;
+---------------+------------------+------+-----+---------+----------------+
| Field         | Type             | Null | Key | Default | Extra          |
+---------------+------------------+------+-----+---------+----------------+
| ValueID       | int(10) unsigned |      | PRI | NULL    | auto_increment |
| CustomFieldID | int(11) unsigned | YES  | MUL | NULL    |                |
| Value         | varchar(25)      | YES  |     | NULL    |                |
+---------------+------------------+------+-----+---------+----------------+
3 rows in set (0.10 sec)

mysql> SELECT cf.customfieldid, cf.name, cf.fieldtype,cf.recordType,cfv.valueid,cfv.value ,cfm.valueID as selected from customfield cf,customfieldvalue cfv left outer join customfieldmultiple cfm on ( cfv.customfieldid = cfm.customfieldid and cfv.valueid = cfm.valueid and cfm.recordid = 1 ),cvtable where cf.customfieldid = cfv.customfieldid and cf.recordtype = cvtable.tableid and  cvtable.name  =  'Entity'  union SELECT cf.customfieldid, cf.name, cf.fieldtype,cf.recordType,null ,cfs.value ,null as seleted from customfield cf,customfieldscalar cfs ,cvtable where cf.customfieldid = cfs.customfieldid and cf.recordtype = cvtable.tableid and  cvtable.name  =  'Entity'  and cfs.recordid = 1 order by cfv.value;
ERROR 1054: Unknown column 'cfv.value' in 'ORDER BY'

mysql> SELECT cf.customfieldid, cf.name, cf.fieldtype,cf.recordType,cfv.valueid,cfv.value ,cfm.valueID as selected from customfield cf,customfieldvalue cfv left outer join customfieldmultiple cfm on ( cfv.customfieldid = cfm.customfieldid and cfv.valueid = cfm.valueid and cfm.recordid = 1 ),cvtable where cf.customfieldid = cfv.customfieldid and cf.recordtype = cvtable.tableid and  cvtable.name  =  'Entity'  union SELECT cf.customfieldid, cf.name, cf.fieldtype,cf.recordType,null ,cfs.value ,null as seleted from customfield cf,customfieldscalar cfs ,cvtable where cf.customfieldid = cfs.customfieldid and cf.recordtype = cvtable.tableid and  cvtable.name  =  'Entity'  and cfs.recordid = 1 order by cfv.Value;
ERROR 1054: Unknown column 'cfv.Value' in 'ORDER BY'
mysql> SELECT cf.customfieldid, cf.name, cf.fieldtype,cf.recordType,cfv.valueid,cfv.value ,cfm.valueID as selected from customfield cf,customfieldvalue cfv left outer join customfieldmultiple cfm on ( cfv.customfieldid = cfm.customfieldid and cfv.valueid = cfm.valueid and cfm.recordid = 1 ),cvtable where cf.customfieldid = cfv.customfieldid and cf.recordtype = cvtable.tableid and  cvtable.name  =  'Entity'  union SELECT cf.customfieldid, cf.name, cf.fieldtype,cf.recordType,null ,cfs.value ,null as seleted from customfield cf,customfieldscalar cfs ,cvtable where cf.customfieldid = cfs.customfieldid and cf.recordtype = cvtable.tableid and  cvtable.name  =  'Entity'  and cfs.recordid = 1;
+---------------+----------+-----------+------------+---------+----------+----------+
| customfieldid | name     | fieldtype | recordType | valueid | value    | selected |
+---------------+----------+-----------+------------+---------+----------+----------+
|             1 | Type     | MULTIPLE  |          1 |       1 | Customer |     NULL |
|             1 | Type     | MULTIPLE  |          1 |       2 | Vendor   |     NULL |
|             1 | Type     | MULTIPLE  |          1 |       3 | Reseller |     NULL |
|             3 | Status   | MULTIPLE  |          1 |       4 | Active   |     NULL |
|             3 | Status   | MULTIPLE  |          1 |       5 | Inactive |     NULL |
|             2 | Industry | SCALAR    |          1 |       0 |          |     NULL |
+---------------+----------+-----------+------------+---------+----------+----------+
6 rows in set (0.09 sec)

How to repeat:
create a table with the structure above, perform the query listed below it.
[26 Nov 2004 14:31] MySQL Verification Team
Hi,

Thank you for the report.
Please, show us the output of SHOW CREATE TABLE for all tables (i.e. customfield, customfieldvalue, customfieldmultiple, customfieldscalar, cvtable).
[26 Nov 2004 16:13] Sergei Golubchik
Please do not submit the same bug more than once. An existing
bug report already describes this very problem. Even if you feel
that your issue is somewhat different, the resolution is likely
to be the same. Because of this, we hope you add your comments
to the original bug instead.

Thank you for your interest in MySQL.

Additional info:

See

http://bugs.mysql.com/bug.php?id=4873
http://bugs.mysql.com/bug.php?id=4156
http://bugs.mysql.com/bug.php?id=4098