SQL Query

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I'm having trouble building an SQL query. I have 2 tables

Students
Name Major ID Year

and

Elections
Title Major Year All


Given the name of a student, I need to find the title all the elections that student can vote in if his Major OR ID matches. Ignore the All field. Here's what I tried but it doesn't return a result:

"SELECT Title FROM Elections INNER JOIN Students ON Elections.Major = Student.Major WHERE Student.Name = '" + name + "'";

This won't even find the ones where the Major matches.
 
Eric said:
I'm having trouble building an SQL query. I have 2 tables

Students
Name Major ID Year

and

Elections
Title Major Year All


Given the name of a student, I need to find the title all the elections
that student can vote in if his Major OR ID matches. Ignore the All field.
Here's what I tried but it doesn't return a result:
"SELECT Title FROM Elections INNER JOIN Students ON Elections.Major =
Student.Major WHERE Student.Name = '" + name + "'";
This won't even find the ones where the Major matches.

Major matches like this:
SELECT elect.Title
FROM Elections elect
, Students stud
WHERE elect.major=stud.major
AND stud.Name = '" + name + "'";

SQL is case-sensitive, so if you're seaching Smith and the database holds
"smith" they're not matching!

I do't understand the ID-field in your student-table. In this query you
cannot use it as a join-condition

Renske.
 
Back
Top