Categories
Technical

Generating random number using mysql query

Using MySQL queries, we can easily generate random numbers using the data we have. Fro example we have a table which has firstname,lastname,age,address,city,pincode in its fields. To generate a random using these data we can use,
select LEFT(firstname,1), LEFT(lastname,1), LEFT(age,2), LEFT(address,2), LEFT(city,1), LEFT(pincode,1) FROM details;

Which can be used as a random number and it can be used like a password from the user’s data itself.
To find the nth largest value in a column

For example we have a employee DB which contains the salary details of all the employees. Suppose if we want to find the employee with third highest salary, we can use
select max(salary) from emp e1 where &n=(select count(salary) from emp e2 where e1.salary<=e2.salary);

By intrepidkarthi

I am Karthikeyan, working as a software professional, interested in Travelling, Bike riding, PC Gaming, Reading Novels, Blogging, Writing thamizh poems.

1 reply on “Generating random number using mysql query”

Talk Me Up is an app designed to give you on demand motivation at the tap of a button – for free! Record and listen to encouraging voice messages to help each other succeed in daily life.

Leave a Reply

Your email address will not be published.