开发者

MySQL ORDER BY column ASC containing two words not correctly alphabetized

开发者 https://www.devze.com 2023-04-10 04:35 出处:网络
I\'m trying to sort the following table: Table: People +---+----------------------+ |id |Ethnicity| +---+----------------------+

I'm trying to sort the following table:

Table: People

+---+----------------------+
|id |       Ethnicity      | 
+---+----------------------+
| 1 | 'Hispanic'           |
| 2 | 'Asian American'     | 
| 3 | 'White'              |
| 4 | 'African American'   | 
| 5 | 'American Indian'    | 
| 6 | 'Other'              |
+---+----------------------+

SQL Query

SELECT DISTINCT Ethnicity FROM People ORDER BY Ethnicity ASC

Results

This generates:

+----------------------+
|       Ethnicity      | 
+----------------------+
| 'American Indian'    |
| 'Asian American'     |
| 'African American'   |
| 'Hispanic'           |
| 'White'              |
| 'Other'              |
+----------------------+

The results I want to generate a开发者_运维技巧re:

+----------------------+
|       Ethnicity      | 
+----------------------+
| 'African American'   |
| 'American Indian'    |
| 'Asian American'     |
| 'Hispanic'           |
| 'Other'              |
| 'White'              |
+----------------------+

Not sure what I'm doing wrong here.


If the data type is an enum, I believe it will order by the item's position (index) in the enum list, not the value of the enum string. Is "American Indian" the first item in your enum definition?

0

精彩评论

暂无评论...
验证码 换一张
取 消