Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Profile Log in to check your private messages Log in
 
Need modification on SQL Query

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
sreekusr
Warnings : 1

New User


Joined: 28 Aug 2006
Posts: 54
Location: Madrid

PostPosted: Fri Jun 05, 2009 8:53 pm    Post subject: Need modification on SQL Query
Reply with quote

Following is the Table


Table1 Having Columns A and B
Code:

Column1    Column2
-------    --------
A             1
B             2            
C             1      
D             1
E              2
S          3
A          2


Following is the Query

Code:
Select Max(Column1) From Table1
Where Column2 = 1;


But i want the value as below

Code:

A
C
D
E

i.e maximum value per unique item in coulmn1 for the Value 1 in Column2

Please suggest how to modify the SQl query to get the result.
Thanks,
Sree
Back to top
View user's profile Send private message

Craq Giegerich

Senior Member


Joined: 19 May 2007
Posts: 1512
Location: Virginia, USA

PostPosted: Fri Jun 05, 2009 9:12 pm    Post subject:
Reply with quote

Code:
Select distinct Column1 From Table1
Where Column2 = 1;
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6970
Location: porcelain throne

PostPosted: Fri Jun 05, 2009 10:26 pm    Post subject:
Reply with quote

to obtain the expected results:
Quote:
But i want the value as below
Code:

A
C
D
E


from the table contents as provided by the TS
Quote:
Table1 Having Columns A and B
Code:

Column1    Column2
-------    --------
A             1
B             2           
C             1     
D             1
E              2
S          3
A          2

the sql would have to be: (with or without the DISTINCT)
Code:

SELECT COLUMN1              <<< or is it COLUMNA ?
FROM TABLE1
WHERE COLUMN2 = 1        <<< or is it COLUMNB ? 
   OR COLUMN1 = 'E'         <<< or is it COLUMNA ?


IF the sreekusr wants something different,
he will have to provide alternative column values
or alternative results as well as consistant column names.
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 -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts query to fetch record which has only ... maxsubrat DB2 12 Mon Dec 11, 2017 5:03 pm
No new posts How to query MAXGENS of an existing P... Chuchulo Hatyzak JCL & VSAM 4 Wed Nov 22, 2017 10:23 pm
No new posts Native SQL Query kishpra DB2 1 Wed Nov 22, 2017 8:38 pm
No new posts Query on IEFBR14 with GDG Ashishpanpaliya JCL & VSAM 4 Tue Nov 07, 2017 8:34 pm
No new posts Query on XMITIP abdulrafi All Other Mainframe Topics 1 Wed Oct 25, 2017 6:54 pm

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us