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?



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.


Sorry Agno, thanks for support, I adjusted the language.

I'm being listed on the screen, so I'm an id too, when I click the draw button hidden friend I want to get my id that I'm using to draw which is the current id, but I also don't want an id that is  being listed in the Sorted IDs column.

The numbers drawn will be saved in the “IdsSorteados” column.  When I click on the button I want him to search for an ID that is not mine because I am also a participant in the draw, but at the same time I also want him to check the “Sorted IDs” column and search for an ID that is not the same  to the IDs in that column.


In order not to bring the ones that have already been drawn, you can do an advanced query before and use the result in your draw query.

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.