[help] esx see if value alreadys exists in database

Hello I would like to know how to see if value already exists in database

local list = MySQL.Sync.fetchAll('SELECT * FROM `empresas`')
print(list) --gives me table:0000236E...

I would like to receive a complete like so i can make like when someone creates a company dont let him have the same name like one of those
image

It returns a result table.

You can get all the results like this:

 local list = MySQL.Sync.fetchAll('SELECT * FROM `empresas`')
print(list[1].empresa_nome) -- This gives you the first result of you query.

I would recommend checking for a name like this:

local nameToCheck = "aa"
local list = MySQL.Sync.fetchAll('SELECT * FROM `empresas` WHERE empresa_nome = ?', {nameToCheck})

if list[1] then
   -- The name exist.
else 
   -- The name dosent exist.
end

Hope that helps. :smiley:

Thank you! Saved me :slight_smile: