jdock1 Posted November 3, 2011 Share Posted November 3, 2011 I have an offer database that I want to order by a few different factors. I would rather order them from top to bottom, top being the most recent added value in the table. I was just wondering what are all of the ordering options? I know you can order by certian values in the table either desc or asc, but when I order from desc by the value in my table "date" its never right. I was kind of hoping that there is a built in function that orders them from most recently added? I would also like to have the option for a user to sort them through the credit value, which is a number from 1-5, with the highest to the lowest descending. It never seems to work when I order them from the number value, its always just random. I'm confused and if anybody can give me some insight I would appreciate it! BTW, Im not a noob I just have never really worked with ordering SQL! Quote Link to comment Share on other sites More sharing options...
jdock1 Posted November 3, 2011 Author Share Posted November 3, 2011 After reading through the manual I still just dont get it. I dont understand WHAT its ordering by when I order it by a certain value. For example when I "ORDER BY date ASC" what is it going by? It just orders it in some damn random fashion? Its so confusing I just want to be able to order from the most recent added. I dont get ordering because when you order by a value it just orders it randomly, like if I wanted to sort it through highest value to lowest how the hell would I word that? Would I have to do something like this: "ORDER BY pointsvalue WHERE pointsvalue = 5 DESC" where 5 is the highest value. Sorry if Im being vague and making no sense I just am frustrated this makes no sense to me its so damn hard to order something! Quote Link to comment Share on other sites More sharing options...
phporcaffeine Posted November 3, 2011 Share Posted November 3, 2011 Okay, we'll need to know a little bit more about your database, specifically the data types of the columns, of the table(s) in question. If, when you order the 'date' field in ascending or descending fashion, it does not order the way you think it should, it may be because of the data type of the column. For instance, a VARCHAR column is treated much differently than a date column; consequently, the data in those columns are treated differently as well. Without knowing much more about your table, I would suggest converting your date columns to TIMPESTAMP columns. It makes ordering and mathematical date operations so much simpler because everything is just an integer. Then, you can order the TIMESTAMP column and the largest integer is the oldest and the smallest integer is the newest. Quote Link to comment Share on other sites More sharing options...
fenway Posted November 3, 2011 Share Posted November 3, 2011 It orders "by" whatever your column type is. 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.