All pastes #919197 Raw Edit

snoyes

public text v1 · immutable
#919197 ·published 2008-02-26 17:44 UTC
rendered paste body
mysql> CREATE TABLE test (country varchar(255));
Query OK, 0 rows affected (0.17 sec)

mysql> INSERT INTO test VALUES ('Uganda'), ('US'), ('Canada'), ('Antigua');
Query OK, 4 rows affected (0.09 sec)
Records: 4  Duplicates: 0  Warnings: 0

mysql> SELECT * FROM test ORDER BY FIELD(country, 'US', 'Canada', country);
+---------+
| country |
+---------+
| US      |
| Canada  |
| Uganda  |
| Antigua |
+---------+
4 rows in set (0.03 sec)

mysql> SELECT * FROM test ORDER BY FIELD(country, 'US', 'Canada', country), country;
+---------+
| country |
+---------+
| US      |
| Canada  |
| Antigua |
| Uganda  |
+---------+
4 rows in set (0.00 sec)

mysql> select * from country order by field(`country`, 'Norway', 'England', `country`);
+-----+---------+
| uid | country |
+-----+---------+
|   5 | Norway  |
|   2 | England |
|   1 | America |
|   3 | France  |
|   4 | Spain   |
|   6 | Sweden  |
+-----+---------+
6 rows in set (0.00 sec)

mysql> select * from country order by field(`country`, 'Norway', 'England', `country`) `country`;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'country`' at line 1