Help finding a random ID other than your own

Guys, I need help.  I have a table called "OrganizaSorteio" and I have the following situation:

 I have the column called "OrganizaSorteio.Id" with the ids 5,6,7,8.

 When I click on the "Sortear" button, I want a valid ID but it will come randomly from the "OrganizaSorteio.Id" table, since this cannot be the Id of the User who is doing the draw and neither can be any of the Ids that have already been drawn.  The IDs that have already been drawn are in the column "OrganizaSorteio.IdSorteado".

 Can you help me?  Is it possible to do only with aggregate?  Is it possible to do with advanced SQL?


Rank: #175

Hi Wallace, how are you.

First, it is a standard to write in english here on the forums, it’s easier for everyone to communicate. 


And about your issue, i have a question about what you wrote:

"sendo que este não pode ser o Id do Usuário que está fazendo o sorteio "

What is this field in your image ?

A possible way to do that, is use this component to generate a randon number, but this componente needs that you to pass a starting and ending range:

So, before execute your aggregate, you need Get the Min and Max Id of your table OrganizaSorteio,

After randon using the component.