# a simple table with userid (id), setting (st) and value (vl): CREATE TABLE `s` ( `id` bigint(11) default NULL, `st` varchar(255) default NULL, `vl` varchar(255) default NULL, KEY `id` (`id`), KEY `st` (`st`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 # I put in some random values: SELECT * FROM s; +------+------+------+ | id | st | vl | +------+------+------+ | 1 | a | 15 | | 1 | b | 64 | | 1 | c | 75 | | 2 | a | 80 | | 2 | b | 78 | | 2 | c | 50 | | 3 | a | 17 | | 3 | b | 32 | | 3 | c | 12 | | 4 | a | 64 | | 4 | b | 81 | | 4 | c | 15 | +------+------+------+ 12 rows in set (0.00 sec) # get the values we're looking for (our sort order): SELECT id, vl AS vl2 FROM s WHERE st = 'c'; +------+------+ | id | vl | +------+------+ | 1 | 75 | | 2 | 50 | | 3 | 12 | | 4 | 15 | +------+------+ 4 rows in set (0.00 sec) # join that to our original table and sort it: SELECT s.* FROM s JOIN (SELECT id, vl AS vl2 FROM s WHERE st = 'c') s2 ON (s.id = s2.id) ORDER BY vl2 ASC, id ASC, st ASC; +------+------+------+ | id | st | vl | +------+------+------+ | 3 | a | 17 | | 3 | b | 32 | | 3 | c | 12 | | 4 | a | 64 | | 4 | b | 81 | | 4 | c | 15 | | 2 | a | 80 | | 2 | b | 78 | | 2 | c | 50 | | 1 | a | 15 | | 1 | b | 64 | | 1 | c | 75 | +------+------+------+ 12 rows in set (0.00 sec)