This code doesn't work and showing error "From keyword not found where expected"
select m.marks,
CASE
WHEN m.marks<65 then 'F'
WHEN m.marks>65 then 'P'
END m.grade
from student s INNER JOIN marks m ON s.id=m.id;
But this works
select marks,
CASE
WHEN marks<65 then 'F'
WHEN marks>65 then 'P'
END grade
from marks
The
m
is an alias for themarks
table, and you use that when referencing columns in that table. You are applying it to a column alias:where it does not belong, so - in that place only - remove the
m.
:As @Gordon pointed out in a comment, you are checking >65 and <65, so a student with exactly 65 will not get either F or P - the grade for them will be null. You probably want:
or
... though if
marks
is null the second version will treat that as F too, while the first will still return null.