View previous topic :: View next topic |
Author |
Message |
arshadh Beginner
Joined: 10 Jan 2007 Posts: 33 Topics: 12
|
Posted: Wed Jun 20, 2007 8:24 am Post subject: NEED help in a query... |
|
|
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 |
|
|
kolusu Site Admin
Joined: 26 Nov 2002 Posts: 12376 Topics: 75 Location: San Jose
|
Posted: Wed Jun 20, 2007 8:52 am Post subject: |
|
|
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 |
|
|
arshadh Beginner
Joined: 10 Jan 2007 Posts: 33 Topics: 12
|
Posted: Wed Jul 11, 2007 11:50 pm Post subject: |
|
|
Thanks Kolusu, the query works fine.. |
|
Back to top |
|
|
|
|