I\'m trying to check if a specific ID exists in a table named \"Products\" in my sqlite database.
def existsCheck( db, id )
temp = db.execute( \"select exist
There is no need to use a subquery:
def existsCheck( db, id )
db.execute( "select 1
from Products
where promoID = ?",
[id] ).length > 0
end
This returns a boolean result.
Change it to:
def existsCheck( db, id )
temp = db.execute( "select 1 where exists(
select 1
from Products
where promoID = ?
) ", [id] ).any?
end
SQL query returns 1
when condition is met or empty result set if it's not. Whole function returns boolean depending on result set.