mysql Rand() not working -


In my case I need to first display special items, apart from that I have to choose randomly. So I have used the following query

  "SELECT * table_test1 WHERE id = 3 UNION (SELECT * FROM table_test1 WHERE id << ORDER BY RAND ())"   

but this randomly

my table

  ID name 1A2B3C4D5E  < /  

It always selects CABDE

Can anyone explain the principle of a union?

What's wrong

use

  In the case of ORDER from SELECT * table_test1 when the id = 3 THEN -1 ELSE RAND () END   

, in the quote comment, in the second statement ORDER BY Has been completely ignored.

That means if you want the whole result to be sorted by a certain sequence then you need the order , which is applicable to the whole query anyway or your solution Depending on the assumptions, implementation may break into future versions.

Comments