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
 

 

Can UNION and COUNT(*) be used in the same select Query.

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

New User


Joined: 01 May 2006
Posts: 6

PostPosted: Wed Apr 18, 2007 4:33 pm    Post subject: Can UNION and COUNT(*) be used in the same select Query.
Reply with quote

Hi! friends..
I got two tables say, 'A' and B'.
'A' has column BIN , REGN and QUES.
Let the values be..
BIN QUES REGN
---- ------- -------
1111 Y 1
2222 N 2
3333 N 1
4444 Y 1

'B' has column BIN and QUES
Let the values be..
BIN QUES REGN
---- ------- --------
1111 N 1
2222 N 2
3333 Y 1
5555 N 2

I want to find how many Y's and N's are there for QUES in Table 'A', also if the BIN is not found in 'A' the query should fetch the BIN from table 'B'.

In my query i'm using COUNT(*) and UNION which is getting the duplicates which i dont want

Answer for the above example should be like....

REGN QUES
-------- --------
1 N 2
1 Y 1
2 N 2
Back to top
View user's profile Send private message

sushil_ach

New User


Joined: 01 May 2006
Posts: 6

PostPosted: Wed Apr 18, 2007 4:44 pm    Post subject:
Reply with quote

Answer for the above example should be like....

REGN QUES
-------- --------
1 -------N --------------2
1 -------Y --------------1
2 -------N ------------- 2

THANX for the help in advance... icon_smile.gif
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 SQL query to run through list of valu... Ni3-db2 DB2 14 Wed Dec 14, 2016 9:52 am
This topic is locked: you cannot edit posts or make replies. Db2 SQL query to convert rows into co... subratarec DB2 5 Thu Nov 17, 2016 4:51 pm


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