mysqlsqlselectmixed

Select mixed value from a column in MySql


I am having registration table, in that student grades are 1,2,3,4,5,6,7,8,9,10,11,12 and after sometimes client has changed the grade values to Grades 1 - 3, Grades 4 - 6, Grades 7 - 12

The MySql DB column has the Grades value of 1,2,3,4,5,6,7,8,9,10,11,12,Grades 1 - 3, Grades 4 - 6, Grades 7 -12.

Now I am creating the report, so I need to filter the grades based on 1,2,3,4,5,6,7,8,9,10,11,12 but I need to select the Grades 1 and also the record has Grades 1 - 3.

If I use the SELECT * FROM registration WHERE Grades LIKE "%1%" means I am also getting the Grades 1,10,12,Grades 1 - 3

enter image description here

Any suggestions or help is appreciated.


Solution

  • This simple answer solves my problem,

    SELECT Grades FROM registration WHERE Grade ="1" OR Grade ="Grades 1 - 3"

    Based on the query from user, using if condition(in php) the Grades in the WHERE clause will be populated.