Unix Technical Forum

Question about using AND in WHERE...

This is a discussion on Question about using AND in WHERE... within the SQL Server forums, part of the Microsoft SQL Server category; --> If I have a three column table, will call it AvailClasses SchoolName, Subject, NumOfClasses --------------------------------------------------------------- Emil, Biology, 3 Emil, ...


Go Back   Unix Technical Forum > Database Server Software > Microsoft SQL Server > SQL Server

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-29-2008, 08:33 PM
JDeats
 
Posts: n/a
Default Question about using AND in WHERE...

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...

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-29-2008, 08:33 PM
markc600@hotmail.com
 
Posts: n/a
Default Re: Question about using AND in WHERE...


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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-29-2008, 08:33 PM
Madhivanan
 
Posts: n/a
Default Re: Question about using AND in WHERE...


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...


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 01:10 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com