Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 a SQL Statement question?

Author  Topic 

mshen
Starting Member

8 Posts

Posted - 2004-09-23 : 22:41:46
Hi Friend,

I have two table: student table and class table

student table like this:

id name
1 tony
2 john
3 darren
4 mark
...

class table like this

is class_id student_id
1 1 1
2 1 3
3 2 3
4 2 4
....

I want to get the the student list who do not select classs 2.I want to know how to write the SQL statement.Please help me.

I write it like this but it doesn't work.

select s.* from student s,class c where s.id=c.student_id and c.class_id<>2

why?

Thanks a lot.

nr
SQLTeam MVY

12543 Posts

Posted - 2004-09-23 : 23:07:50
Condier it without the and c.class_id<>2.
Now take out the ones where c.class_id=2.
That's why you get that resultset.

To do this you need a left outer join or a not exists clause.

==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page
   

- Advertisement -