473,398 Members | 2,368 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

Problem with WHERE IN

4
I've 2 tables students and exams.
Now I've to count the no of students who have appeared for 'n' no of exams.
I used Where in clause but it works more like an 'OR'.

Also the list of exams is passed through a parameter and the no is not fixed.
How do I check for students that have appeared in all the exams in the list.
I hope I've made the question clear.

TIA
Nov 16 '06 #1
7 2195
willakawill
1,646 1GB
I've 2 tables students and exams.
Now I've to count the no of students who have appeared for 'n' no of exams.
I used Where in clause but it works more like an 'OR'.

Also the list of exams is passed through a parameter and the no is not fixed.
How do I check for students that have appeared in all the exams in the list.
I hope I've made the question clear.

TIA
Hi. Not too difficult if you post the table structures please.
Nov 16 '06 #2
Tokci
4
Hi. Not too difficult if you post the table structures please.
Sorry sould have done that earlier...actually there are 3 tables :

Expand|Select|Wrap|Line Numbers
  1. Students
  2.  -StudentID  (PK)
  3.  -Student Name
  4.  
  5. Exams
  6.  -ExamID  (PK)
  7.  -Description
  8.  
  9. Details
  10.  -DetailID (Identity)
  11.  -ExamID  (FK)
  12.  -StudentID  (FK)
I need no of students who have appeared in the chosed exams.
Nov 16 '06 #3
willakawill
1,646 1GB
Sorry sould have done that earlier...actually there are 3 tables :

Expand|Select|Wrap|Line Numbers
  1. Students
  2.  -StudentID  (PK)
  3.  -Student Name
  4.  
  5. Exams
  6.  -ExamID  (PK)
  7.  -Description
  8.  
  9. Details
  10.  -DetailID (Identity)
  11.  -ExamID  (FK)
  12.  -StudentID  (FK)
I need no of students who have appeared in the chosed exams.
OK Try this out
Expand|Select|Wrap|Line Numbers
  1. SELECT COUNT([StudentID])
  2. FROM Details D
  3. INNER JOIN Exams E
  4. ON D.ExamID = E.ExamID
  5. WHERE E.Description = 'put your description here'
  6.  
Nov 16 '06 #4
Tokci
4
OK Try this out
Expand|Select|Wrap|Line Numbers
  1. SELECT COUNT([StudentID])
  2. FROM Details D
  3. INNER JOIN Exams E
  4. ON D.ExamID = E.ExamID
  5. WHERE E.Description = 'put your description here'
  6.  

This won't help 'coz I need the no of students appeared in ALL the chosen exams.
ie. if I select English Hindi and Maths....I must get the total no of students that appeared in all the 3 exams.

If I use "E.descrition = " , I can only specify one description and if I use "E.Description in" the result I get is not what I want...it returns the no of students who have given 1 or more than 1 of the exams selected.

I hope this time I'm able to clearly state the problem.
Nov 20 '06 #5
willakawill
1,646 1GB
This won't help 'coz I need the no of students appeared in ALL the chosen exams.
ie. if I select English Hindi and Maths....I must get the total no of students that appeared in all the 3 exams.

If I use "E.descrition = " , I can only specify one description and if I use "E.Description in" the result I get is not what I want...it returns the no of students who have given 1 or more than 1 of the exams selected.

I hope this time I'm able to clearly state the problem.
OK try this:
Expand|Select|Wrap|Line Numbers
  1. SELECT Exams.Description, COUNT([Details].[StudentID])
  2. FROM Details D
  3. INNER JOIN Exams E
  4. ON D.ExamID = E.ExamID
  5. GROUP BY E.Description
  6.  
Nov 20 '06 #6
Tokci
4
OK try this:
Expand|Select|Wrap|Line Numbers
  1. SELECT Exams.Description, COUNT([Details].[StudentID])
  2. FROM Details D
  3. INNER JOIN Exams E
  4. ON D.ExamID = E.ExamID
  5. GROUP BY E.Description
  6.  

This will simply give the no of students for EACH exam.
Will give u another example :
Suppose there are 3 exams - x1, x2, x3
we have 5 students - a,b,c,d,e

Now,
a,b,c,d,e have given x1
b,c,d have given x2
a,d,e have given x3

that means if I want to know the no of students who have given all the exams then count should be 1 (Only B has given all the 3 exams). Similarily if I choose x1,x3 the it should return 3 (a,d,e).

Where as with our current query it will simply return :
x1 - 5
x2 - 3
x3 - 3

(I hope I'm interpretting ur query right).

BTW I really appreciate ur prompt replies and help.
Nov 21 '06 #7
willakawill
1,646 1GB
Sorry sould have done that earlier...actually there are 3 tables :

Expand|Select|Wrap|Line Numbers
  1. Students
  2.  -StudentID  (PK)
  3.  -Student Name
  4.  
  5. Exams
  6.  -ExamID  (PK)
  7.  -Description
  8.  
  9. Details
  10.  -DetailID (Identity)
  11.  -ExamID  (FK)
  12.  -StudentID  (FK)
I need no of students who have appeared in the chosed exams.
Give this one a run around the block :)
Expand|Select|Wrap|Line Numbers
  1. SELECT COUNT([StudentID]}
  2. FROM Details D
  3. INNER JOIN Exams E
  4. ON D.ExamID = E.ExamID
  5. WHERE StudentID IN (
  6. SELECT StudentID
  7. FROM Details D
  8. INNER JOIN Exams E
  9. ON D.ExamID = E.ExamID
  10. WHERE StudentID IN (
  11. SELECT StudentID
  12. FROM Details D
  13. INNER JOIN Exams E
  14. ON D.ExamID = E.ExamID
  15. WHERE E.Description = 'Maths'
  16. )
  17. AND E.Description = 'English'
  18. )
  19. AND E.Description = 'SQL Programming'
  20.  
Nov 21 '06 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Keith Dewell | last post by:
Greetings! My current job has brought me back to working in C++ which I haven't used since school days. The solution to my problem may be trivial but I have struggled with it for the last two...
3
by: Nicolas Payre | last post by:
Hi, I have the following SQL that I want to use to update a table. It doesn't work ! Does someone knows why? ** I Know it could be done easy with a CURSOR FOR LOOP, but still... Thanks for...
117
by: Peter Olcott | last post by:
www.halting-problem.com
4
by: Bradley Burton | last post by:
I'm using Allen Brown's code for audit logging (http://allenbrowne.com/AppAudit.html), but I'm having a problem. My aud table doesn't populate with the tracking info at all. I think it might be a...
102
by: Skybuck Flying | last post by:
Sometime ago on the comp.lang.c, I saw a teacher's post asking why C compilers produce so many error messages as soon as a closing bracket is missing. The response was simply because the compiler...
20
by: Development - multi.art.studio | last post by:
Hello everyone, i just upgraded my old postgres-database from version 7.1 to 7.4.2. i dumped out my 7.1 database (with pg_dump from 7.1) as an sql-file with copy-commands and to one file using...
0
by: mjsterz | last post by:
I've been working with VB .NET for less than a year and this is the first time I've posted on one of these groups, so let me apologize beforehand if I'm being unclear, not posting my issue...
15
by: sara | last post by:
I have a Memo field in a table to hold notes from a conversation a social worker has had with a client (this is for a non-profit). If the user needs to update the memo field, I need to find the...
1
by: Alex Vinokur | last post by:
Hi, I have compilation problem on SUN CC compiler with template while using option -m64 (64-bit addressing model). No problem while using option -m32 (32-bit addressing model) $ CC -V CC:...
2
by: swethak | last post by:
Hi, I am getting the problem the problem with google map in Internet Explorer. This map worked fine in mozilla . When i opened the same map in Internet Explorer i am getting the error...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.