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
 

 

Slcting addnal column outside DISTINCT in a select query

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

New User


Joined: 27 Dec 2005
Posts: 58

PostPosted: Mon Jun 09, 2008 2:27 pm    Post subject: Slcting addnal column outside DISTINCT in a select query
Reply with quote

We are currently modifying a CICS-DB2 prod pgm which has a main menu map which shows address summary and then on selecting S on the record displays a full address on the next screen.

MAIN MAP:
OPTION NAME TRADE ZIP CODE CITY
S DAVID XXXXXXXX 08012 KANSAS

DETAIL MAP(XCTL from MAIN MAP):This would have the complete address.

To achieve this we had a prod query which looks like:
SELECT DISTINCT(For the main map summary)
a.name
,a.trade
,a.zip code
,a.city
FROM table1 a
,table2 b
WHERE a.key = b.key(KEY would be a selection variable entered on the main map).We had some issues with -811 coming on the detail screen since a particular NAME had multiple addresses in several LOCS in same city.

Hence we are trying to change this query to also send the LOC NUMBER to the detail program:
SELECT DISTINCT
a.name
,a.trade
,a.zip code
,a.city
,a.LOCNUM
this would help in uniquely identifying the address.

However when we do this the DISTINCT on the main map is getting affected.
EX:
DAVID XXXXXXXX 08012 KANSAS
DAVID XXXXXXXX 08012 KANSAS

Suppose we had these 2 addresses fetched in main map query then because of DISTINCT it would have sent 1 row to the map but now it would send 2 rows since we are also fetching the loc num.Since the loc num is not required on the map it ends up looking like entire duplicate rows on the main map.

Is there any way we can get the loc number in the same query without affecting the original 4 columns.So we should get 1 row and also get the loc num for the next program.
Back to top
View user's profile Send private message

stodolas

Active Member


Joined: 13 Jun 2007
Posts: 632
Location: Wisconsin

PostPosted: Mon Jun 09, 2008 6:50 pm    Post subject:
Reply with quote

Quote:

Is there any way we can get the loc number in the same query without affecting the original 4 columns.So we should get 1 row and also get the loc num for the next program.


The short answer to this is: No there is not a way to accomplish this.
---------------------------------------------------------------------------------------
How is the user to know if LOCNUM 1 or LOCNUM 4 is the one they should be choosing?

Say you have this in your table
Code:

Bob   plumber   90210   Beverly Hills   1
Bob   plumber   90210   Beverly Hills   2
Bob   plumber   90210   Beverly Hills   3
Bob   plumber   90210   Beverly Hills   4
Bob   plumber   90210   Beverly Hills   5

Am I correct in stating that you only want the following for your main screen?
Code:

Bob   plumber   90210   Beverly Hills   5

Because by using DISTINCT in your first query you have no idea which LOCNUM you are getting. It could be 1,2,3,4, or 5 the result is indeterminate.

If you don't SELECT LOCNUM initially and do a select after the user has made a selection on the screen, how will you know which one is the correct LOCNUM if they are all the same except for the LOCNUM?
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