If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > inactivate order by in a statement

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-06-10, 12:20
bono56 bono56 is offline
Registered User
 
Join Date: May 2004
Posts: 133
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.
__________________
Lyrics Database: www.shermani.com
Reply With Quote
  #2 (permalink)  
Old 11-06-10, 12:22
shammat shammat is offline
Registered User
 
Join Date: Nov 2003
Posts: 2,408
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
Reply With Quote
  #3 (permalink)  
Old 11-07-10, 00:39
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
Quote:
Originally Posted by bono56 View Post
i already sort my records in view
how did you do this?
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #4 (permalink)  
Old 11-09-10, 05:38
bono56 bono56 is offline
Registered User
 
Join Date: May 2004
Posts: 133
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.
__________________
Lyrics Database: www.shermani.com
Reply With Quote
  #5 (permalink)  
Old 11-09-10, 05:42
bono56 bono56 is offline
Registered User
 
Join Date: May 2004
Posts: 133
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.
__________________
Lyrics Database: www.shermani.com
Reply With Quote
  #6 (permalink)  
Old 11-09-10, 05:54
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
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
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #7 (permalink)  
Old 11-09-10, 06:18
shammat shammat is offline
Registered User
 
Join Date: Nov 2003
Posts: 2,408
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

Quote:
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")
Reply With Quote
  #8 (permalink)  
Old 11-09-10, 17:19
bono56 bono56 is offline
Registered User
 
Join Date: May 2004
Posts: 133
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
__________________
Lyrics Database: www.shermani.com

Last edited by bono56; 11-09-10 at 17:30.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On