Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Need query to find a column value

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
View previous topic :: :: View next topic  
Author Message
noorkh

New User


Joined: 06 Mar 2006
Posts: 76
Location: Chennai

PostPosted: Wed Jul 02, 2008 3:11 pm    Post subject: Need query to find a column value
Reply with quote

Hi,

I have below requirements.

My table name. TDMTABLE

There are 2 columns say. TDM_POL_KEY and TDM_THG_KEY.

I would like to find out (is there 2 THG_KEY found for same POL_KEY).

For eg:
----------------------------
POL_KEY | THG_KEY |
----------------------------
21 | 101 |
21 | 101 |
22 | 102 |
22 | 103 |
23 | 104 |
23 | 104 |
-----------------------------

In the above table keys, for POL_KEY 22, i have 2 different THG_KEY 102 and 103.

Can any one let me know the query to find out such POL_KEY?
Back to top
View user's profile Send private message

ashimer

Active Member


Joined: 13 Feb 2004
Posts: 551
Location: Bangalore

PostPosted: Wed Jul 02, 2008 5:42 pm    Post subject:
Reply with quote

For your example the query wud be

Code:


SELECT TDM_POL_KEY FROM (
SELECT TDM_POL_KEY,COUNT(DISTINCT TDM_THG_KEY) AS TCOUNT
FROM TDMTABLE
GROUP BY TDM_POL_KEY) AS TEMP WHERE TCOUNT > 1;





Quote:

I would like to find out (is there 2 THG_KEY found for same POL_KEY).


you need to find out if there exists only 2 diff keys and not less ??

wht is the o/p required if the data is

----------------------------
POL_KEY | THG_KEY |
----------------------------
21 | 101 |
22 | 102 |
22 | 103 |
23 | 104 |
-----------------------------
Back to top
View user's profile Send private message
nabarundas

New User


Joined: 21 Jun 2007
Posts: 28
Location: pune

PostPosted: Thu Jul 03, 2008 10:23 am    Post subject: reply...
Reply with quote

Hi noorkh,

Try the following query

select pol_key from TDMTABLE
group by pol_key
having count(distinct thg_key) > 1


Regards,
Nabarun
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2 All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Join in SQL Query vickey_dw DB2 2 Tue Jan 17, 2017 12:15 am
This topic is locked: you cannot edit posts or make replies. MQ setup query mohitsaini Java & MQSeries 4 Sun Jan 08, 2017 1:53 am
No new posts DB2 query Using Recursion, Converting... smilewithashu2 DB2 1 Tue Jan 03, 2017 12:50 pm
No new posts find particular member name in PDS us... ravi243 CLIST & REXX 10 Mon Dec 19, 2016 6:44 pm
No new posts SQL query to run through list of valu... Ni3-db2 DB2 14 Wed Dec 14, 2016 9:52 am


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us