Sorry, your question is unclear and/or your database is wrongly designed, because
schoold.id
and
class.id
can NOT be equal! A database model should looks like:
1 School => ∞ YearBooks
1 YearBook => ∞ Classes
1 Class => ∞ Students
So, you need at least 4 objects (tables):
1.
Yearbooks
table - describes a school year
2.
Classes
table - contains all classes, each entry describes a class for a particular school year
3.
Students
table - contains all registered students, each entry describes a particular student
4.
StudentsInClass
table - (many to many relationship between students and classes) contains
ids
of class and student
BTW: I'd recommend to replace old-fashioned SQL programming
Select distinct c.id as id,c.Name
from class as c, school as s
where c.id=s.id
order by 1
to new one (using
Join's[
^]):
SELECT DISTINCT c.id as id, c.Name
FROM class as c
INNER JOIN school as s ON c.id=s.id
ORDER BY c.id
For further details, please see:
Visual Representation of SQL Joins[
^]
When you finish changing a database model and queries into proper ones, i'd recommend to to study this site:
http://linq101.nilzorblog.com/linq101-lambda.php[
^]
It might be helpfull in understang how to write Linq queries using lambda expressions.