Showing posts with label sql. Show all posts
Showing posts with label sql. Show all posts
Tuesday, July 23, 2013
Force some rows to appear last in SQL
Everyone who writes SQL knows ORDER BY, which forces the result to be ordered by the values in the specified column. I had a scenario where I not only needed to ordered by the values in a column but also wanted a certain value to appear last. Naturally I go to Google first and as usual it found me what I needed from StackOverflow. See this post, which was about forcing rows to appear first. For my purpose I just needed to flip the 0 and 1 in the CASE-WHEN. BTW, if one still wants the results to be ordered by that column, simply add that column after the CASE-WHEN in ORDER BY.
Subscribe to:
Posts (Atom)