Home » SQL & PL/SQL » SQL & PL/SQL » Result in same rows (plsql)
Result in same rows [message #635024] Thu, 19 March 2015 05:04 Go to next message
mehboob110233
Messages: 55
Registered: February 2014
Location: Pakistan
Member

Dear all,
how can i remove empty cell in this query.
print screen attached.


Quote:
SELECT HOLDING, OPERATING_ROOM, PACU
FROM (SELECT MRNO HOLDING, NULL OPERATING_ROOM, NULL PACU
FROM ORDERENTRY.PATIENT_CURRENT_LOCATION
WHERE ORDER_LOCATION_ID = '313'
UNION
SELECT NULL HOLDING, MRNO OPERATING_ROOM, NULL PACU
FROM ORDERENTRY.PATIENT_CURRENT_LOCATION
WHERE ORDER_LOCATION_ID = '072'
UNION
SELECT NULL HOLDING, NULL OPERATING_ROOM, MRNO PACU
FROM ORDERENTRY.PATIENT_CURRENT_LOCATION
WHERE ORDER_LOCATION_ID = '413')

/forum/fa/12561/0/
[mod-edit: image inserted into message body by bb]
  • Attachment: query.png
    (Size: 42.43KB, Downloaded 982 times)

[Updated on: Mon, 03 August 2015 14:12] by Moderator

Report message to a moderator

Re: Result in same rows [message #635026 is a reply to message #635024] Thu, 19 March 2015 05:38 Go to previous messageGo to next message
Lalit Kumar B
Messages: 3174
Registered: May 2013
Location: World Wide on the Web
Senior Member
You need to explain why you are using UNION. The three union queries could be written in a single query:

SELECT HOLDING, OPERATING_ROOM, PACU
   FROM ORDERENTRY.PATIENT_CURRENT_LOCATION
 WHERE ORDER_LOCATION_ID in ('313','072','413');


Also, you don't have to use quote tags to post the code. Use code tags.

[Updated on: Thu, 19 March 2015 05:39]

Report message to a moderator

Re: Result in same rows [message #635031 is a reply to message #635026] Thu, 19 March 2015 06:13 Go to previous messageGo to next message
mehboob110233
Messages: 55
Registered: February 2014
Location: Pakistan
Member

I get here three option if order_location_id='313' then get employee code as holding
if order_location_id='072' then get employee code as operating_room
if order_location_id='413' get employee code as pacu

this give me result as show in picture
how can i remove empty lines.
Re: Result in same rows [message #635037 is a reply to message #635031] Thu, 19 March 2015 07:00 Go to previous messageGo to next message
John Watson
Messages: 8931
Registered: January 2010
Location: Global Village
Senior Member
Use Lalit's query, but enclose the three column names in a COALESCE function.
Re: Result in same rows [message #635047 is a reply to message #635037] Thu, 19 March 2015 07:53 Go to previous messageGo to next message
mehboob110233
Messages: 55
Registered: February 2014
Location: Pakistan
Member

Thanks sir,

But here i need three column as HOLDING, OPERATING_ROOM, PACU
for order_location_id.
Re: Result in same rows [message #635051 is a reply to message #635047] Thu, 19 March 2015 08:44 Go to previous messageGo to next message
cookiemonster
Messages: 13920
Registered: September 2008
Location: Rainy Manchester
Senior Member
You realise that you've got no relationship between the three columns so you can get different combinations every time you run the query?
Re: Result in same rows [message #635054 is a reply to message #635047] Thu, 19 March 2015 08:47 Go to previous messageGo to next message
Michel Cadot
Messages: 68645
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

Please read OraFAQ Forum Guide and How to use [code] tags and make your code easier to read.
Also always post your Oracle version, with 4 decimals.

With any SQL or PL/SQL question, please, Post a working Test case: create table (including all constraints) and insert statements along with the result you want with these data then we will be able work with your table and data. Explain with words and sentences the rules that lead to this result.

Re: Result in same rows [message #635055 is a reply to message #635037] Thu, 19 March 2015 09:13 Go to previous messageGo to next message
cookiemonster
Messages: 13920
Registered: September 2008
Location: Rainy Manchester
Senior Member
John Watson wrote on Thu, 19 March 2015 12:00
Use Lalit's query, but enclose the three column names in a COALESCE function.


He's only getting null cause he specifically coded it in the original query so he could have three columns in each select. It's doubtful you'll get the same nulls with Lalit's query, so coalesce won't help.
Re: Result in same rows [message #635056 is a reply to message #635055] Thu, 19 March 2015 09:24 Go to previous message
Lalit Kumar B
Messages: 3174
Registered: May 2013
Location: World Wide on the Web
Senior Member
I agree, COALESCE was in my mind, however, OP has not told the reason for using UNION to append the result sets, and thus using NULL for respective columns. I guess that's why John suggested COALESCE as OP has not explained the relationship.
Previous Topic: SQL date overlapping
Next Topic: Need to identify columns not referenced in UPDATE SET clause.
Goto Forum:
  


Current Time: Thu Apr 25 01:34:33 CDT 2024