Q:

Return boolean on mysql select statment after comparing values of particular column

I have a module table which has weightage and course id columns. Multiple modules with different weights can be added to a course. I need to compare the weights of all modules added to a course and return true if all weights are equal, false otherwise.

id   name   weight   course_id
 1    A       30       112
 2    B       40       112
 3    C       20        87
 4    D       23        87
 5    E       10        97
 6    F       10        97

I need the select query to return true if the weights for the modules(E and F), added to the course with id 97  are equal, false otherwise
Thanks in advance

A:

I need to compare the weights of all modules added to a course and return true if all weights are equal, false otherwise

Try this:  
select 
  course_id, count( distinct weightage ) = 1 as matched
from my_table
group by course_id  

