How to get some randomized concats based on 2 columns from 1 table?
i have a large user Database (13k+), and for some reason i need to create random names. The users table has "first_name" and "last_name". Now i want to have 10 concats of full_name and last_name of two completely random rows. Is that even possible with SQL?
My other idea was just to create a full_names and last_names table … but that would'nt be as much challenging.
Oh, and i开发者_开发技巧t should not take up too much performance :) (so order by rand() is not an option ;))
I don't understand "10 concats of full_name and last_name of two completely random rows", so this probably won't be your final answer, but it should lead you in the right direction. For a more complete answer, please provide some sample output of what you're looking for, and your database schema.
This should generally be done in code, not in SQL. However, it is possible in SQL. There is one requirement. You must have an incremental integer key column. For example, the key should start at 1 and end at 13000.
The RAND() implementation may vary, depending on your database vendor.
Here's the query:
SELECT CONCAT(u1.first_name, ul.last_name) AS full_name
FROM users
WHERE mykey = FLOOR(1 + (RAND() * 13000))
If the key has gaps, it gets a bit trickier, and the randomness will favor the gaps, so I hope there are no gaps.
精彩评论