-1

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.

Shadow
  • 33,525
  • 10
  • 51
  • 64
Boopathi D
  • 361
  • 2
  • 21

1 Answers1

0

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.

Boopathi D
  • 361
  • 2
  • 21
  • Does it? It seems you have to know all the possible formats when searching for grade 1 - that's not really what programming is about - what would happen if grade 1 - 6 appeared without your knowledge..When writing code you should make it as general as possible to capture all the known and as many of the unknowns you can imagine. – P.Salmon Oct 05 '20 at 14:34
  • And trap any unimagined unknowns elsewhere so that you can finesse your code. – P.Salmon Oct 05 '20 at 14:35
  • @P.Salmon As I already said it is select box which has fixed value currently `Grades 1 - 3`, `Grades 4 - 6`, `Grades 7 - 12` – Boopathi D Oct 05 '20 at 14:36