MySQL SELECT COUNT > 0 as boolean value

mysql

Solution

In your example you are not using the `greater than` operator, but a `bit shift (>>)`. If you use

SELECT COUNT(*) > 0 AS my_bool FROM table GROUP BY id;

my_bool will contain 0 or 1 as boolean value.

Problem

I'm trying to get a true/false value in a column in a select statement which indicates if a count is >0 or not. I read these docs: http://dev.mysql.com/doc/refman/5.1/en/expressions.html Which I don't fully understand but they seemed to indicate I could use '>>' in my expression. So I tried this: ``` SELECT COUNT(*)>>0 AS my_bool FROM table GROUP BY id; ``` It runs and doesnt generate errors or warnings, however the `my_bool` column just contains the results of the `COUNT(*)`. Is what I'm trying to do possible, if so how? P.S Yes I know I could just test for x>y in my code that handles the results, I want to know if it is something that can be done in MySQL alone (feel free to explain why it's not advisable, by all means)

Original source