Skip to content

Tag: random

Hide duplicate column cells in view

First of all, this here doesn’t solve my problem at all. I tried this too. I want generate random unique fake data (first name and address) I used the following SQL request: The result apparently looked like this (the addresses repeat themselves for the next name too): How do I make the first names AND …

SQL Select random rows partitioned by a column

I have a dataset looks like this and i need a query which returns 2 random values from where country in (‘a’, ‘c’): Answer This should work: Replace rand() with random() if you’re using Postgres or newid() in SQL Server.

Update columns based on calculation

My table looks like this: I have a list of id’s connected to datestamps. I can manage to calculate the difference between their latest and first entry as follows: However, I am unsure how I can update my table to reflect these calculations. What I want is the following: Answer In MySQL, you can self-joi…

Generating never used before random number in SQL

I am using the function below to generate a random number between 0 and 99999999999. However, I need to make sure that the returned number has never been used before in the same app. In .net I would create a while loop and keep looping until the returned value is not found in a table that stores previously us…