Jump to content
php.lv forumi

ORDER BY x DESC


KarlisBa

Recommended Posts

Sveiki!

Ir kādas idejas kādam kā ar vienu vaicājumu varētu no MySQL db izvilkt pēc id grupējot no 1-10 ierakstus, bet teiksim 5. ierakstu parādīt kā pēdējo nevis starp 4. un 6. bet aiz 10? Slinkums rakstīt kodu, kas to aprēķinātu. :)

Edited by KarlisBa
Link to comment
Share on other sites

Vispār jau nebūtu slikti arī pievienot atbildi nākotnes meklētājiem, ja citiem ievajagas :)

Viens no variantiem varētu būt (numurs 3 būs tas ko likt beigās):

mysql> create table x (x int);
Query OK, 0 rows affected (0.11 sec)

mysql> insert into x values (1), (2), (3), (4), (5);
Query OK, 5 rows affected (0.05 sec)
Records: 5  Duplicates: 0  Warnings: 0

mysql> SELECT * FROM x
   -> ORDER BY if(x=3,100,x);
+------+
| x    |
+------+
|    1 |
|    2 |
|    4 |
|    5 |
|    3 |
+------+
5 rows in set (0.00 sec)

 

Gints Plivna

http://datubazes.wordpress.com

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...