By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,730 Members | 1,156 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,730 IT Pros & Developers. It's quick & easy.

SQL Query

P: n/a
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.
Nov 15 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a

"Eric" <an*******@discussions.microsoft.com> wrote in message
news:9A**********************************@microsof t.com...
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.
Nov 15 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.