Results 1 to 8 of 8
  1. #1
    Join Date
    May 2004
    Posts
    144

    Unanswered: inactivate order by in a statement

    hi
    is there any special phrase which use instead of "x" in "ORDER BY x", that inactivate order by?
    in WHERE i use something like "1=1" , it is always true & make WHERE section useless.
    i already sort my records in view, so i dont need "ORDER BY" section, & off course i cant omit "ORDER BY" part from my queries.

  2. #2
    Join Date
    Nov 2003
    Posts
    2,935
    Provided Answers: 12
    Although I fail to understand what you are trying to achieve, using a constant value for the ORDER BY should do what you want:
    Code:
    SELECT * 
    FROM your_table
    ORDER BY 42

  3. #3
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    Quote Originally Posted by bono56 View Post
    i already sort my records in view
    how did you do this?
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  4. #4
    Join Date
    May 2004
    Posts
    144
    Quote Originally Posted by shammat View Post
    Although I fail to understand what you are trying to achieve, using a constant value for the ORDER BY should do what you want:
    Code:
    SELECT * 
    FROM your_table
    ORDER BY 42
    tanX, but it didnt work out, i tested "ORDER BY 1" & "ORDER BY TRUE", but it seems mysql changed sorting. i want something neutral, like it doesnt exist. (like: WHERE 1=1), something that hasnt any effect o statement.

  5. #5
    Join Date
    May 2004
    Posts
    144
    Quote Originally Posted by r937 View Post
    how did you do this?
    i have view like this:

    Code:
    CREATE VIEW `vwMyTable` AS 
    SELECT *
    FROM `tbMyTable`
    ORDER BY point DESC;
    the result already sorted by a field. now in php db interface class i have to send an order by clause as a parameter to function. it is possible to send it, but i wondered if there are anything like 1=1 in WHERE clauses for ORDER BY, something neutral that doesn't have any effect on my result set.

  6. #6
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    Quote Originally Posted by bono56 View Post
    the result already sorted by a field.
    that's somewhat problematic, isn't it

    i would advise you (and others would as well) not to have an ORDER BY clause in the view

    as for the "something neutral" option that you are looking for, i don't do php myself but i do know that it has an IF statement, so the thing to do is to actually make use of this functionality of your application language, and for those instances where you do not want the data sorted, omit the ORDER BY clause entirely
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  7. #7
    Join Date
    Nov 2003
    Posts
    2,935
    Provided Answers: 12
    Quote Originally Posted by r937 View Post
    i would advise you (and others would as well) not to have an ORDER BY clause in the view
    I was surprised that it's possible at all

    omit the ORDER BY clause entirely
    That would be my recommendation as well.

    But remember: if you don't use ORDER BY, any sort order you see, is pure coincidence.
    It is not guaranteed that this order will remain the same over time.
    (this is because a relational table has - per definition - no "order")

  8. #8
    Join Date
    May 2004
    Posts
    144
    Quote Originally Posted by r937 View Post
    as for the "something neutral" option that you are looking for, i don't do php myself but i do know that it has an IF statement,
    i mentioned php as an example, i just looking for a sql statement solution.
    & about neutral, in phpMyAdmin when you click on SQL tab, it insert a sql satement like "SELECT * FROM tb1 WHERE 1", i called "WHERE 1" a neutral part, it does nothing. i wonder maybe something like that exist for ORDER BY that i always pass to function, when i don't need sorting & off course i can't pass nothing!

    Quote Originally Posted by r937 View Post
    omit the ORDER BY clause entirely
    suppose it not possible, cause i can't change some sections on a big app, designed by someone else.
    i searched a lot & it seems there is not something for this. however it's not a big problem, i just was curious if somthing like that exists, tanX guys
    Last edited by bono56; 11-09-10 at 18:30.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •