[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: About union sql Mysql 4.x


Hello.

If you want all records with item=1 to be at the beginning and
sorted in a random order you can use this query:

select * from tablea order by if(item=1,0,1),  rand();


HALIL DEMIREZEN wrote:
> What if i want to list all the records not limiting them to a constant?
> 
> 
> 
> ------------------------------------------------------------
> Halil Demirezen 
> System Support Engineer/ Sistem Destek Muhendisi 
> Mobile Tel/Cep Tel: +90(543) 502 04 42
> E-Mail/E-Posta: suppressed
> -----------------------------------------------------------
> 
> 
> 
> 
> Gleb Paharenko <suppressed> 
> 05.12.2005 12:19
> 
> To
> suppressed
> cc
> 
> Subject
> Re: About union sql  Mysql 4.x
> 
> 
> 
> 
> 
> 
> Hello.
> 
> 
> 
> From http://dev.mysql.com/doc/refman/5.0/en/union.html:
> 
> 
> 
> "ORDER BY for individual SELECT statements within parentheses has an
> 
> effect only when combined with LIMIT. Otherwise, the ORDER BY is
> 
> optimized away."
> 
> 
> 
> 
> 
> Therefore you're getting the same results, because ORDER BY doen't
> 
> work for your query.
> 
> 
> 
> 
> 
> 
> 
> HALIL DEMIREZEN wrote:
> 
> 
>>Hi,
> 
> 
> 
>>I am trying to run an sql query such as below to list items=x randomly 
> 
> and 
> 
> 
>>then items != x randomly.. 
> 
> 
> 
> 
>>mysql> (select * from tablea where item=1 order by rand()) union all 
> 
> 
>>(select  * from tablea where item != 1 order by rand());
> 
> 
> 
>>but the result is not as expected. rand() seems not to be working...
> 
> 
> 
>>What can be the problem? or what can be the difference between my will 
> 
> and 
> 
> 
>>the exact result of the query?
> 
> 
> 
>>Thanks..
> 
> 
> 
> 
>>------------------------------------------------------------
> 
> 
>>Halil Demirezen 
> 
> 
>>System Support Engineer/ Sistem Destek Muhendisi 
> 
> 
>>Mobile Tel/Cep Tel: +90(543) 502 04 42
> 
> 
>>E-Mail/E-Posta: suppressed
> 
> 
>>-----------------------------------------------------------
> 
> 
> 
> 
> 


-- 
For technical support contracts, goto https://order.mysql.com/?ref=ensita
This email is sponsored by Ensita.NET http://www.ensita.net/
   __  ___     ___ ____  __
  /  |/  /_ __/ __/ __ \/ /    Gleb Paharenko
 / /|_/ / // /\ \/ /_/ / /__   suppressed
/_/  /_/\_, /___/\___\_\___/   MySQL AB / Ensita.NET
       <___/   www.mysql.com




-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/suppressed


Mail converted by mhonarc 2.6.15
This archive provided courtesy of JSW4.NET, Internet Hosting Services for Small Business.