woolyg Posted July 29, 2008 Share Posted July 29, 2008 Hi, I'm having a brainfreeze, could someone help? CREATE TABLE IF NOT EXISTS `players` ( `player_id` int(11) unsigned NOT NULL auto_increment, `player_name` varchar(64) collate latin1_general_ci NOT NULL, PRIMARY KEY (`player_id`), FULLTEXT KEY `player_name` (`player_name`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci; INSERT INTO `soccer_players` VALUES (1, 'Player1'); INSERT INTO `soccer_players` VALUES (2, 'Player2'); INSERT INTO `soccer_players` VALUES (3, 'Player3'); INSERT INTO `soccer_players` VALUES (4, 'Player4'); INSERT INTO `soccer_players` VALUES (5, 'Player5'); INSERT INTO `soccer_players` VALUES (6, 'Player6'); INSERT INTO `soccer_players` VALUES (7, 'Player7'); INSERT INTO `soccer_players` VALUES (8, 'Player8'); INSERT INTO `soccer_players` VALUES (9, 'Player9'); INSERT INTO `soccer_players` VALUES (10, 'Player10'); I'm trying to select 5 player_id, ordered by player_id DESC, then output them as follows: 5 - 6 - 7 - 8 - 9 - 10 Can anyone help? Thanks, WoolyG Quote Link to comment Share on other sites More sharing options...
Barand Posted July 29, 2008 Share Posted July 29, 2008 Just so I understand, you want to select 5 (is that any 5 at random ?) players, sorted in descending order. From that selection you then want to output 6 players in ascending order? Is that right? Quote Link to comment Share on other sites More sharing options...
woolyg Posted July 29, 2008 Author Share Posted July 29, 2008 I'm sorry, the brainfreeze is obviously affecting my communication too.. I'm using: SELECT players.player_id FROM players ORDER BY players.player_id DESC LIMIT 5 ..but that's outputting 10,9,8,7,6 ..and I'd *like* to output 6,7,8,9,10 (where 10 is the very highest player_id) Do you get me? sorry for the confusion... W Quote Link to comment Share on other sites More sharing options...
Barand Posted July 29, 2008 Share Posted July 29, 2008 try SELECT player_id FROM (SELECT player_id FROM players ORDER BY player_id DESC LIMIT 5) as x ORDER BY player_id Quote Link to comment Share on other sites More sharing options...
woolyg Posted July 29, 2008 Author Share Posted July 29, 2008 Thanks for that - I don't fully understand how it works, but it does.. What if I wanted to output 6(Player6), 7(Player7), 8(Player8), 9(Player9), 10(Player10) ..is that possible? Thanks, WoolyG Quote Link to comment Share on other sites More sharing options...
Barand Posted July 29, 2008 Share Posted July 29, 2008 Yes, you'd need the CONCAT() function Quote Link to comment Share on other sites More sharing options...
woolyg Posted July 29, 2008 Author Share Posted July 29, 2008 Thanks Barand, I'll get reading into it! - WoolyG Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.