Skip to content
Advertisement

Get a random record from table where a field is null

I am trying to retrieve a random apartment from the database table where the ownerID is null. This script is used for a GTA 5 Server on AltV the problem is the letrandomHouse = Math.floor(Math.random()*res.length); it wont update the Apartment’s owner where id is

Full Export Function

Advertisement

Answer

A problem with your code is the WHERE clause in the SELECT statement:

This will never match. To check for nullness, you need the IS NULL construct.

But as far as concerns, you can do what you want with a single statement:

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement