What is the meaning of SELECT EXISTS (SELECT 1 FROM favoritelist WHERE id=:id) in:
@Query("SELECT EXISTS (SELECT 1 FROM favoritelist WHERE id=:id)")
public int isFavorite(int id);
Advertisement
Answer
SELECT EXISTS (SELECT 1 FROM favoritelist WHERE id=:id)
The exists condition evaluates whether at least one row exists in favoritelist where id matches the given parameter. The outer query evaluates the condition in numeric context, and returns 1 if the condition is satisfied, else 0.
In a nutshell:
if at least one record exists in
favoritelistwhoseidmatches the parameter, the query returns1else, it returns
0