Reputation: 105
Hi I have table called mytable and 1 column first_name , how can I check if 'John' is in this table and return the result as true/false.
Upvotes: 0
Views: 608
Reputation: 636
You can utilize a EXISTS-query:
select exists (select * from mytable where mytable.first_name = 'John')
The above query will return a boolean which will be true if the sub-query inside the braces returns any rows at all; the boolean will false if the sub-query return no rows.
Upvotes: 2
Reputation: 522074
SELECT CASE WHEN COUNT(*) > 0 THEN 'true' ELSE 'false' END
FROM mytable
WHERE first_name LIKE '%John%'
Upvotes: 0
Reputation:
SELECT count(*) FROM mytable WHERE first_name LIKE 'John';
returns number of occurrences. If there is no John in table, returns zero.
Upvotes: 0