When a Rand() is called, it displays random numbers between 0 and 1.

 

You can use Select statement to call Rand() Function:

 

For example,

Select Rand(), Rand();

Rand()

Rand()

0.45832146952763

0.72513571983465

 

It can be seen above that, 2 different values are displayed each time.

To randomize a set of rows or values, you can use ORDER BY RAND() as follows:

 

Let us consider the following Students table:

roll_no

name

total_marks

(out of 600)

percentage

grade

1

Ashok

392

65.33

B

2

Chaitali

454

75.67

A

3

Smriti

502

83.60

A

4

Kaushik

337

56.10

C

 

Example:

Now, use the following commands:

Select * From Students Order By Rand();

 

roll_no

name

total_marks

(out of 600)

percentage

grade

2

Chaitali

454

75.67

A

3

Smriti

502

83.60

A

1

Ashok

392

65.33

B

4

Kaushik

337

56.10

C

 

Select * From Students Order By Rand();

 

roll_no

name

total_marks

(out of 600)

percentage

grade

4

Kaushik

337

56.10

 C

1

Ashok

392

65.33

B

2

Chaitali

454

75.67

A

3

Smriti

502

83.60

A

 

From the above examples it is clearly seen at each time when a Rand() is invoked, it displays a different results.