IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Need modification on SQL Query


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
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
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
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: 6966
Location: porcelain throne

PostPosted: Fri Jun 05, 2009 10:26 pm
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 View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts RC query -Time column CA Products 3
No new posts Dynamically pass table name to a sele... DB2 2
No new posts Query on edit primary command CLIST & REXX 5
No new posts Query on edit primary command CLIST & REXX 1
No new posts Issue with EXEC CICS QUERY SECURITY c... CICS 6
Search our Forums:

Back to Top