PDA

View Full Version : How do I create and AND Where clause?


bob_moran
05-12-02, 21:35
Hello,

I have a table that has rows of student_id's and class_codes.

How do I SELECT people that have taken multiple classes?

If I say

WHERE class_code = '1' AND class_code = '2' AND class_code = '3'

No rows get returned because no single row could have all three values in it.

I think I need some sort of nested SELECT statment, or VIEW, but what do I know?!

Thanks in advance,

Bob Moran

alligatorsql.com
05-13-02, 06:35
Hello,

if you need only the student identifier than use something like this:

select student, count(1) from table group by username
having count(1) > 1

Hope that helps

Manfred Peter
(Alligator Company)
http://www.alligatorsql.com

Gyro
05-28-02, 05:35
If you would like to get the student id and names who have multiple classes.

select table2.student,table1.name from table1 inner join
(select student from table2 group by student
having count(student) > 1) as table2 on table2.student=table1.student

whereas:
table1 = student master file
table2 = enrollment transaction file
student = unique student id