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
 

 

Returning multiple rows for one row in the table

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

New User


Joined: 02 Aug 2011
Posts: 17
Location: India

PostPosted: Thu May 09, 2013 3:14 pm    Post subject: Returning multiple rows for one row in the table
Reply with quote

Hi ,

I have an Employee table which has employee records, I need to write a query which fetches employee records from the table based on certain criteria and also for each employee i need more than one output records in the result set of the query.

Example :

Code:
EMP_NO   EMP_Name   DOJ                 
101           Satish          01-05-2009
102           Srinu            04-20-2010

Output
Code:
EMP_NO   EMP_NAME       DOJ             WORK_SHIFT
101           Satish          01-05-2009          D
101           Satish          01-05-2009          N
102           Srinu            04-20-2010          D
102           Srinu            04-20-2010          N

How do we achieve this in SQL ?

Thanks in Advance

Satish ..
Back to top
View user's profile Send private message

Pandora-Box

Moderator


Joined: 07 Sep 2006
Posts: 1529
Location: Andromeda Galaxy

PostPosted: Thu May 09, 2013 3:26 pm    Post subject:
Reply with quote

Tr this

Code:
SELECT EMP_NO ,EMP_Name, DOJ,'D'
FROM <TABLENAME>
WHERE <CONDITION>
UNION ALL
SELECT EMP_NO ,EMP_Name, DOJ,'N'
FROM <TABLENAME>
WHERE <CONDITION>
;
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 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
No new posts Row-Numbers of distinct rows? Auryn DB2 1 Thu Oct 20, 2016 4:38 pm
No new posts Need Rexx Program to Load in to DB2 T... Hareesh Verma CLIST & REXX 22 Tue Sep 20, 2016 2:59 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us