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

Question about using AND in WHERE...

P: n/a
If I have a three column table, will call it AvailClasses

SchoolName, Subject, NumOfClasses
---------------------------------------------------------------
Emil, Biology, 3
Emil, Chemistry, 1
Emil, Calculus, 4
Prestwood, Biology, 2
Prestwood, Chemistry, 4
Prestwood, Calculus, 2
Westhaven, Biology, 1
Westhaven, Chemistry, 2
Westhaven, Calculus, 4

Using this subset of data as an example, I'd like to write a sql query
to return the results of all schools that have at least 2 Bilology
classes and at at least 4 Calculus classes

The query I came up with looks like this... It doesn't work.

SELECT SchoolName FROM AvilClasses WHERE
(Subject = 'Biology' AND NumOfClasses > 1) AND (Subject = 'Calculus'
AND NumOfClasses > 3).

The query above results in an empty set...

Jun 1 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a

This has already been answered in
microsoft.public.sqlserver.programming

Jun 1 '06 #2

P: n/a

Do not post same question in multiple forums

Madhivanan
JDeats wrote:
If I have a three column table, will call it AvailClasses

SchoolName, Subject, NumOfClasses
---------------------------------------------------------------
Emil, Biology, 3
Emil, Chemistry, 1
Emil, Calculus, 4
Prestwood, Biology, 2
Prestwood, Chemistry, 4
Prestwood, Calculus, 2
Westhaven, Biology, 1
Westhaven, Chemistry, 2
Westhaven, Calculus, 4

Using this subset of data as an example, I'd like to write a sql query
to return the results of all schools that have at least 2 Bilology
classes and at at least 4 Calculus classes

The query I came up with looks like this... It doesn't work.

SELECT SchoolName FROM AvilClasses WHERE
(Subject = 'Biology' AND NumOfClasses > 1) AND (Subject = 'Calculus'
AND NumOfClasses > 3).

The query above results in an empty set...


Jun 2 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.