MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

NEED help in a query...

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database
View previous topic :: View next topic  
Author Message
arshadh
Beginner


Joined: 10 Jan 2007
Posts: 33
Topics: 12

PostPosted: Wed Jun 20, 2007 8:24 am    Post subject: NEED help in a query... Reply with quote

Consider a table having emp_id and dep_id.

Code:
EMP_ID    DEP_ID   
   100       1     
   101       1     
   102       1     
   103       2     
   104       2     
   105       3     
   106       3     
   107       3     
   108       2     
   109       2     
   110       3     
   111       4     


I want only one emp_id (any one- random) from a department.

My output shud be like
Code:

  EMP_ID    DEP_ID   
    102       1       
    105       3       
    108       2       
    111       4     
[/code].

Help me getting a rite query
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12376
Topics: 75
Location: San Jose

PostPosted: Wed Jun 20, 2007 8:52 am    Post subject: Reply with quote

arshadh,

If you don't really care as to which emp_id you get just simply use MIN/Max column functions.

ex:

Code:

SELECT MIN(EMP_ID)   
      ,DEP_ID       
  FROM T1           
 GROUP BY DEP_ID     


or

Code:

SELECT MAX(EMP_ID)   
      ,DEP_ID       
  FROM T1           
 GROUP BY DEP_ID     


Kolusu
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
arshadh
Beginner


Joined: 10 Jan 2007
Posts: 33
Topics: 12

PostPosted: Wed Jul 11, 2007 11:50 pm    Post subject: Reply with quote

Thanks Kolusu, the query works fine..
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group