SitePoint Sponsor |
|
User Tag List
Results 1 to 7 of 7
Thread: Order by
-
Nov 3, 2009, 05:23 #1
- Join Date
- Feb 2005
- Posts
- 737
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Order by
Hi,
I have a simple tbl like so with 100's of records in it:
id | name | order
----------------
1 | Jon | 0
2 | Jim |1
3 | Fred | 0
Now, I want to include all of these records in a query but I was wondering if there was any way I could order by asc starting from 1 rather than Zero?
Thanks
-
Nov 3, 2009, 05:31 #2Code SQL:
SELECT * FROM tbl ORDER BY `order` ASC;
-
Nov 3, 2009, 05:41 #3
- Join Date
- Feb 2005
- Posts
- 737
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Yes, but that wll start the order at 0 though I want it to start at 1???
-
Nov 3, 2009, 06:49 #4
- Join Date
- Jul 2002
- Location
- Toronto, Canada
- Posts
- 39,347
- Mentioned
- 63 Post(s)
- Tagged
- 3 Thread(s)
ORDER BY CASE WHEN order=0 THEN 937 END, order
-
Nov 3, 2009, 07:59 #5
- Join Date
- Feb 2005
- Posts
- 737
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Thanks!
-
Nov 3, 2009, 08:06 #6
- Join Date
- Feb 2005
- Posts
- 737
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Out of interest if I then wanted to order by another two columns after this ie:
Code:, published DESC , id DESC
Code:SELECT * FROM `test_stories` ORDER BY CASE WHEN order =0 THEN order =1, published DESC , id DESC
-
Nov 3, 2009, 08:13 #7
- Join Date
- Jul 2002
- Location
- Toronto, Canada
- Posts
- 39,347
- Mentioned
- 63 Post(s)
- Tagged
- 3 Thread(s)
Bookmarks