Home » SQL & PL/SQL » SQL & PL/SQL » query help (oracle 10g)
query help [message #435244] Tue, 15 December 2009 05:54 Go to next message
rajasekhar857
Messages: 500
Registered: December 2008
Senior Member
SELECT EPMD.MEDICAL_DATA_ID
      ,EPMD.DIABETES_MEDICALDATA_ID
      ,EPMD.MEDICAL_DATA_VALUE
      ,EPMD.MEDICAL_DATA_DATE
      ,EDCCD.CC_DATA_NAME
      ,EPMD.ENCOUNTER_ID 
FROM EMRPatientMedicalData EPMD 
     INNER JOIN EMRDiabetesMedicalDataLkp EDMD ON EPMD.DIABETES_MEDICALDATA_ID=EDMD.DIABETES_MEDICALDATA_ID 
     INNER JOIN EMRDiabetesCCDataLkup EDCCD ON EDMD.DIABETES_MEDICALDATA_ID=EDCCD.CC_DATA_ID 
       AND EDCCD.CATEGORY_ID=1001  
       AND EDCCD.CC_DATA_ID=1002 
WHERE EPMD.PATIENT_ID=3157 
AND  (EPMD.ENCOUNTER_ID IS NULL 
   OR EPMD.ENCOUNTER_ID IN (SELECT ENCOUNTER_ID 
                            FROM   EMREncounterDetails 
                            WHERE  IS_SAVE_FOR_LATER=0 
                            AND PATIENT_ID=3157)
     )
AND MEDICAL_DATA_VALUE IS NOT NULL 
ORDER BY EPMD.MEDICAL_DATA_DATE DESC



2 record are coming as i want only 1st record please help me

[format code]

[Updated on: Tue, 15 December 2009 06:07] by Moderator

Report message to a moderator

Re: query help [message #435246 is a reply to message #435244] Tue, 15 December 2009 05:58 Go to previous messageGo to next message
delna.sexy
Messages: 941
Registered: December 2008
Location: Surat, The Diamond City
Senior Member
Do you want help without giving any details?

To get only first record you can use ROWNUM = 1.

regards,
Delna
Re: query help [message #435247 is a reply to message #435246] Tue, 15 December 2009 06:00 Go to previous messageGo to next message
rajasekhar857
Messages: 500
Registered: December 2008
Senior Member
i used but am not getting the values
Re: query help [message #435248 is a reply to message #435247] Tue, 15 December 2009 06:06 Go to previous messageGo to next message
delna.sexy
Messages: 941
Registered: December 2008
Location: Surat, The Diamond City
Senior Member
Where did you use it?
Query doesn't contain anything like ROWNUM.

And to get better and quick help, provide enough details.

regards,
Delna
Re: query help [message #435249 is a reply to message #435244] Tue, 15 December 2009 06:08 Go to previous messageGo to next message
JRowbottom
Messages: 5933
Registered: June 2006
Location: Sunny North Yorkshire, ho...
Senior Member
Do the two rows that you're getting contain identical or different values?
Re: query help [message #435250 is a reply to message #435249] Tue, 15 December 2009 06:15 Go to previous messageGo to next message
rajasekhar857
Messages: 500
Registered: December 2008
Senior Member
containing different values
Re: query help [message #435261 is a reply to message #435244] Tue, 15 December 2009 06:40 Go to previous messageGo to next message
pablolee
Messages: 2834
Registered: May 2007
Location: Scotland
Senior Member
Quote:
2 record are coming as i want only 1st record please help me
How do you define first?
Re: query help [message #435277 is a reply to message #435250] Tue, 15 December 2009 07:19 Go to previous messageGo to next message
JRowbottom
Messages: 5933
Registered: June 2006
Location: Sunny North Yorkshire, ho...
Senior Member
If there are multiple, distinct rows coming back and you only want one, then your query is wrong.
If you were going to do things properly, you would need to look at the WHERE and JOIN conditions and work out where the extra row is coming from, and add extra conditions to restrict the set of rows.

If, as I suspect, you just want a crappy fix to restrict you to the first row returned without caring if it's the correct one, you can do;
SELECT *
FROM (<your query>)
WHERE rownum = 1
Re: query help [message #435278 is a reply to message #435244] Tue, 15 December 2009 07:23 Go to previous messageGo to next message
cookiemonster
Messages: 12403
Registered: September 2008
Location: Rainy Manchester
Senior Member
Since the original query has an order by it could well be that top-n - your suggestion - is the correct fix.
Of course it would help if the OP specifically told us.

[Updated on: Tue, 15 December 2009 07:24]

Report message to a moderator

Re: query help [message #435280 is a reply to message #435278] Tue, 15 December 2009 07:25 Go to previous messageGo to next message
JRowbottom
Messages: 5933
Registered: June 2006
Location: Sunny North Yorkshire, ho...
Senior Member
In the past the OP has shown no particular concern about which of multiple rows he gets back.

The pessimist in me doubts that this time will be any different
Re: query help [message #435283 is a reply to message #435280] Tue, 15 December 2009 07:29 Go to previous message
pablolee
Messages: 2834
Registered: May 2007
Location: Scotland
Senior Member
JRowbottom wrote on Tue, 15 December 2009 13:25
The pessimist in me doubts that this time will be any different

I'm thinking that realist may be more appropriate a term here Wink
Previous Topic: In which year maximum number of employees has been recruited(hire date)using employees table(oracle)
Next Topic: Alphanumeric
Goto Forum:
  


Current Time: Fri Dec 02 16:33:05 CST 2016

Total time taken to generate the page: 0.21418 seconds