I have a problem in the MySQL Query:
How can i SELECT something but when it errors because it doesn´t exist it should return a value like 1 or something else.
My Query
SELECT License FROM fivem_auth WHERE IP = '34.45.34.77';
There is no error when a row doesn't exist. It simply returns no rows. If you are expecting one value, here are two methods that return NULL
instead:
SELECT (SELECT License FROM fivem_auth WHERE IP = '34.45.34.77') as Licence;
SELECT MAX(License)
FROM fivem_auth
WHERE IP = '34.45.34.77';
For either of these, you can use COALESCE()
to returns a non-NULL
value. But NULL
seems appropriate for no value in the table.
You can
UNION
your query with a query that returns the default if the row doesn't exist.