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
 General SQL Server Forums
 New to SQL Server Programming
 filtering one group

Author  Topic 

pipoD
Starting Member

3 Posts

Posted - 2009-10-29 : 09:07:49
Can anyone help me here? I am not very good with SQL query yet.

table1
ID Group Ref
1 a 0
2 a 1
3 b 0
4 b 1
5 b 2
6 c 0
7 c 1
8 c 2
9 d 1
10 d 0

as you can see from the table,
1 and 2 belong to group a
3,4 and 5 belong to group b
6,7, and 8 belong to group c
9 and 10 belong to group d

How can i write a query to filter out the group a and d only?
Tons of thanks in advance =D

senthil_nagore
Master Smack Fu Yak Hacker

1007 Posts

Posted - 2009-10-29 : 09:14:57
select * from table_name where group in('a','d')

Senthil.C
------------------------------------------------------
[Microsoft][ODBC SQL Server Driver]Operation canceled

http://senthilnagore.blogspot.com/
Go to Top of Page

pipoD
Starting Member

3 Posts

Posted - 2009-10-29 : 09:39:59
ohhhh..okay~ i see~ Thanks a lot!!!
but what if the group is not alphabet and its a whole list of numbers of few hundred records? cant possibly search all the numbers right?
something like

ID-Group-Ref
1-123-0
2-123-1
3-221-0
4-221-1
5-221-2
6-311-0
7-311-1
8-311-2
9-445-0
10-445-1
.
.
.
Go to Top of Page

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2009-10-29 : 09:56:55
You could do something like this
where group like '%-xxx-%' or group like '%-yyy-%',etc.

Jim

Everyday I learn something that somebody else already knew
Go to Top of Page
   

- Advertisement -