0

I want to rearrange mysql table rows for example

column1 | column2 | column3
1         abc       abc
2         def       def
3         ghi       ghi

after some procedure

column1 | column2 | column3
2         def       def
1         abc       abc
3         ghi       ghi

means randomly rearrange existing table

NOTE: I cant use rand() in mysql query for some reason

Harsh Soni
  • 70
  • 1
  • 1
  • 7

2 Answers2

0

Try like this:-

SELECT * FROM tableName ORDER BY RAND();
Hussain Shabbir
  • 14,801
  • 5
  • 40
  • 56
0

For selecting a single row, you can use this method:

For a I suppose column1 is the Primary Key of the table.

Now I use another method to solve this issue.

SELECT MIN(column1), MAX(column1) FROM tablename;

Fetch the result into $a

//php code

$column1=rand($a[0],$a[1]);

SELECT * FROM tablename WHERE column1>='$column1' LIMIT 1

Now you may try something like[I am not sure about the result]:

SELECT * FROM tablename  ORDER BY column1=RAND(0,3);

Here 3 is the maximum range expected for column1.

Ataboy Josef
  • 2,087
  • 3
  • 22
  • 27