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: 6968
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 Create procedure issues -628 when add... chandraBE DB2 1 Mon Sep 18, 2017 12:16 pm
No new posts Can we limit length in concatenation ... balaji81_k DB2 7 Tue Aug 22, 2017 2:50 am
No new posts Need DB2 query to fetch previous row ! Chandan1993 DB2 10 Sat Jun 03, 2017 10:43 am
No new posts JCL to Set Return code based on DB2 S... vinu78 DB2 17 Mon Mar 13, 2017 9:47 pm
No new posts SQL query not working in Cobol program. CuriousMainframer COBOL Programming 14 Wed Feb 22, 2017 5:56 pm

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