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: 1537
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 Changeman get multiple "Browse C... elixir1986 Compuware & Other Tools 4 Fri Jul 14, 2017 1:48 am
No new posts Loading data to table gives wrong for... Raghu navaikulam DB2 19 Thu Jul 13, 2017 2:11 pm
No new posts How to write Specific Fields from Mul... Padhu SYNCSORT 6 Thu Jul 06, 2017 10:26 am
No new posts compare 2 rows within the same file ram_vizag SYNCSORT 7 Wed Jun 14, 2017 12:34 am
No new posts Unable to create multiple files using... mbattu COBOL Programming 3 Fri May 05, 2017 5:35 pm


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