I currently have a signed integer set in a MyISAM table,
The query is like:
SELECT * from some_view ORDER BY value DESC, dateAdded DESC
I’m getting this order:
1
2
-1
-2
0
0
The zero values aren’t seen as +/- but I need them to be greater than a negative value!!!
This is my actual query:
SELECT * FROM vw_answer sa left join vw_answer_votes av on av.answerID = sa.id WHERE sa.id = 77 ORDER BY av.vote, dateAdded
I have the following:
tbl_users
tbl_solutions - Indexes tbl_users.id as authorID
tbl_solution_answers - Indexes tbl_solutions.id as solutionID
tbl_solution_answer_votes - Indexes tbl_users.id as voterID and tbl_solution_answers
as answerID
tbl_solution_answer_votes only has one none indexed column which contains -1 or 1 depending on the vote cast by a user. This is a signed integer.
my view when I select answers selects tbl_solution_answers and the sum(tbl_solution_answer_votes.vote)
It all works, except the ordering on signed integer.
Edit: Values in the votes table only exist if a user has voted else it simply doesn’t exist. I need something like this I think:
SELECT * FROM tbl_answers sa right join vw_answer_votes av on av.answerID = sa.id
ORDER BY av.vote > 0 desc, av.vote IS NULL, av.vote < 0 desc, dateAdded DESC
You are ordering on two fields, value and dateadded, try taking out your date added.
I inserted some random values and here are the results:
Notice in the order, 0 > -1.