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
 SQL Server Development (2000)
 query for retrieving data

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2002-04-29 : 10:31:11
kavita writes "i have two tables in one there is subject and other fields and in other table i have subjectid which is primary key in the first table and categoryid , which describes diff. categories whether this is for male and for age ggroup and like this ,i am putting subjectid for each category like
Ex:


subjectid categoryid
1 2
1 3
2 2
2 4


where '2' is for example for male category and '3' for age group '18',and '4' for '60' age group ,now i want the subject which is for male but for the age group '18' only , now as there are two enteries for the '2' category
and if i write query like
"SELECT * FROM TABLE WHERE CATEGORYID=2 OR CATEGORYID=3 "
it will return me 2 number subjectid also ,which i dont require as it is for the age group '60' only .
so can you sugggest me some query for that as early as possible.

SQL VER: MS-SQL 2000"

Edited by - merkin on 04/29/2002 19:22:04

Nazim
A custom title

1408 Posts

Posted - 2002-04-29 : 10:35:18
SELECT * FROM TABLE WHERE CATEGORYID in(2,3)
and subjectid <> 2

HTH

--------------------------------------------------------------
Go to Top of Page

AjarnMark
SQL Slashing Gunting Master

3246 Posts

Posted - 2002-04-29 : 19:07:45
Nazim, methinks you were sleepy or lazy. Your answer seems too specific to the example, and not quite up to your usual standards. How about:

SELECT subjectid
FROM Table
WHERE CategoryID in (2,3)
GROUP BY SubjectID
HAVEING Count(*) >= 2

Subject ID 2 will be skipped because it only matches one of the two Category criteria.

Go to Top of Page
   

- Advertisement -