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
 

 

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: 45
Location: Mumbai

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: 6966
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 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