How can this be achieved in SQL???????

Hi Guys,
This is my query:
SELECT  distinct iy.trial_no,
       iypa.amendment_no,
       iy.country_code,
       iy.country_desc,
       iypa.amend_reg_submission_date,
       iypa.amend_reg_approval_date,
       iypa.amend_reg_comments,
       iyea.ea_amendment_submission_date,
       IYEA.ea_amendment_approval_date,
       iyea.ea_amendment_expiry_date,
       iyea.ea_approval_comments,
    iyea.master_approval_flag      
FROM   irt_trc_protocol_amendment iypa,
       irt_trc_ethical_approvl_amend iyea,
       irt_trial_country iy
WHERE  iypa.trial_no = iyea.trial_no
AND    iypa.amendment_no = iyea.amendment_no
AND    iypa.country_code = iyea.country_code
AND    iypa.trial_no=101416
AND    iy.trial_no= iypa.trial_no
AND    iypa.country_code = 'GBR'
AND    iypa.country_code = iy.country_code 
AND    iyea.amendment_no = 4
AND    IYEA.master_approval_flag = 1 The above query will only ever return one row because only one record can have it's master_approval_flag set to 1. However multiple records can have a master_approval_flag set to 0.
This is what I want my query to acheive:
Select the one row where master_approval_flag = 1. If there is no record where master_approval_flag = 1, then still only display one row but ommit the details from the IYEA table and only include
the data from the IYPA table - Such that the output will only ever return one row....
How can I do this?
Thanks!

This should work:
select t.*
SELECT  distinct
       iy.trial_no,
       iypa.amendment_no,
       iy.country_code,
       iy.country_desc,
       iypa.amend_reg_submission_date,
       iypa.amend_reg_approval_date,
       iypa.amend_reg_comments,
       iyea.ea_amendment_submission_date,
       IYEA.ea_amendment_approval_date,
       iyea.ea_amendment_expiry_date,
       iyea.ea_approval_comments,
       iyea.master_approval_flag
      ,row_number() over (order by iyea.Master_Approval_Flag desc) rn
FROM   irt_trc_protocol_amendment     iypa,
       irt_trc_ethical_approvl_amend  iyea,
       irt_trial_country              iy
WHERE  iypa.trial_no                  = iyea.trial_no
AND    iypa.amendment_no              = iyea.amendment_no
AND    iypa.country_code              = iyea.country_code
AND    iypa.trial_no                  = 101416
AND    iy.trial_no                    = iypa.trial_no
AND    iypa.country_code              = 'GBR'
AND    iypa.country_code              = iy.country_code 
AND    iyea.amendment_no              = 4
) t
where rn = 1You could possibly remove the DISTINCT and specify
      ,row_number() over (order by iyea.Master_Approval_Flag desc, iy.Tria_No, iy.Amendment_No) rn
-- instead of
,row_number() over (order by iyea.Master_Approval_Flag desc) rnSince you are guranteed to always return a single row there may be no reason to use DISTINCT, which would probably slow the query down somewhat.

Similar Messages

  • Need to pass out parameter in middle of a process. How can this be achieved

    Package test_pkg
    procedure main_prc(x_stat out varchar2)
    insert_prc(l_stat);
    x_stat:=l_stat;
    valid_prc
    end main_prc;
    procedure insert_prc(x_stat1 out varchar2)
         insert into staging table
         x_stat:='S';
    end insert_prc;
    procedure valid_prc
         validate staging table data
    end valid_prc;
    end test_pkg;
    Requirement: Need to pass out parameter in middle of a process. How can this be achieved?

    Use return at any time to get the out variable, but this will stop the process.

  • I need to intercept all local files that are being loaded in Firefox. How can that be achieved?

    I am using geckofx in c#. I need to intercept response of a local file load request so that I can modify some data/response before it reaches Javascript.
    In short, I need something like
    1. JS requests browser to read a file.
    2. Browser reads content of a file.
    3. MAKE SOME MODIFICATIONS TO DATA (Additional Step)
    4. Then pass this modified data to JS to perform required tasks.
    Is this possible? If yes, how can this be achieved.

    You may need to rebuild permissions on your user account. To do this,boot to your Recovery partition (holding down the Command and R keys while booting) and open Terminal from the Utilities menu. In Terminal, type:  ‘resetpassword’ (without the ’s), hit return, and select the admin user. You are not going to reset your password. Click on the icon for your Macs hard drive at the top. From the drop down below it select the user account which is having issues. At the bottom of the window, you'll see an area labeled Restore Home Directory Permissions and ACLs. Click the reset button there. The process takes a few minutes. When complete, restart.   
    Repair User Permissions

  • How can I enable embedded pl/sql gateway to run on port 80

    I have a new 11G install on OEL 4.0, database created. I would like to be
    able to access the instance using the pl/sql gateway. Works fine with
    port 8080, the default. How to I enable it to run on port 80?
    I found this statement in the following docuementation:
    http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14259/xdb22pro.htm#ADXDB2500
    Using HTTP(S) on Nonstandard Ports
    By default, HTTP listens on a nonstandard, unprotected port: 8080. To use HTTP(S) on
    the standard port, such as 80, your DBA must chown the TNS listener to setuid ROOT
    rather than setuid ORACLE, and configure the port number in the Oracle XML DB
    configuration file /xdbconfig.xml.I have root priviledges on the box.
    I've tried setting the listener file permissions:
    chown root:dba /u01/app/oracle/product/11.1.0/db_1/bin/tnslsnr
    chmod 6775 /u01/app/oracle/product/11.1.0/db_1/bin/tnslsnr
    Also put root in the dba group.
    The permissions turn out like this:
    -rwsr-sr-x 1 root dba 830854 Jun 17 21:04 /u01/app/oracle/product/11.1.0/db_1/bin/tnslsnr
    I stopped the listener, bounced the database, and started the listener again.
    But it still shows the process being owned by oracle:
    oracle 29682 1 0 21:08 ? 00:00:00 /u01/app/oracle/product/11.1.0/db_1/bin/tnslsnr LISTENER -inherit
    Changing the port is easy:
    Connected to:
    Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - Production
    With the Partitioning, OLAP, Data Mining and Real Application Testing options
    SYS>select dbms_xdb.gethttpport as "HTTP-Port" , dbms_xdb.getftpport as "FTP-Port" from dual;
    HTTP-Port FTP-Port
    8080 2100
    At this point, I can access the apex home page with the following url:
    http://hostname:8080/apex/f?p=4550:10:1454849288245548
    I can than change it to port 80:
    SYS>begin
    dbms_xdb.sethttpport('80');
    dbms_xdb.setftpport('2100');
    end;
    2 3 4 5
    PL/SQL procedure successfully completed.
    SYS>SYS>select dbms_xdb.gethttpport as "HTTP-Port" , dbms_xdb.getftpport as "FTP-Port" from dual;
    HTTP-Port FTP-Port
    80 2100
    When I try to access apex with the following url:
    http://rmdcopslnx1.us.oracle.com/apex/f?p=4550:10:1454849288245548
    I get the following:
    Failed to Connect
    Firefox can't establish a connection to the server at hostname.com.
    Though the site seems valid, the browser was unable to establish a connection.
    * Could the site be temporarily unavailable? Try again later.
    * Are you unable to browse other sites? Check the computer's network connection.
    * Is your computer or network protected by a firewall or proxy? Incorrect settings
    * can interfere with Web browsing.I can set the port. Just can't talk to it.
    This is the entry from the listener log:
    <msg time='2008-07-03T15:40:09.741-06:00' org_id='oracle' comp_id='tnslsnr'
    type='UNKNOWN' level='16' host_id='hostname'
    host_addr='xxx.xxx.xxx.xxx'>
    <txt>TNS-12546: TNS:permission denied
    TNS-12560: TNS:protocol adapter error
    TNS-00516: Permission denied
    Linux Error: 13: Permission denied
    </txt>
    </msg>
    So this looks like an permissions problem. But where? I posted
    this on the apex forum here:
    Re: How can I enable embedded pl/sql gateway to run on port 80
    They suggested asking here.

    No, that thread did not provide the information that I need. Some more data:
    I have the port set to 8080:
    Connected to:
    Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - Production
    With the Partitioning, OLAP, Data Mining and Real Application Testing options
    SYS>select dbms_xdb.gethttpport as "HTTP-Port" , dbms_xdb.getftpport as "FTP-Port" from dual;
    HTTP-Port FTP-Port
    8080 2100
    At this point, I can access the apex home page with the following url:
    http://hostname:8080/apex/f?p=4550:10:1454849288245548
    I can than change it to port 80:
    SYS>begin
    dbms_xdb.sethttpport('80');
    dbms_xdb.setftpport('2100');
    end;
    2 3 4 5
    PL/SQL procedure successfully completed.
    SYS>SYS>select dbms_xdb.gethttpport as "HTTP-Port" , dbms_xdb.getftpport as "FTP-Port" from dual;
    HTTP-Port FTP-Port
    80 2100
    When I try to access apex with the following url:
    http://rmdcopslnx1.us.oracle.com/apex/f?p=4550:10:1454849288245548
    I get the following:
    Failed to Connect
    Firefox can't establish a connection to the server at hostname.com.
    Though the site seems valid, the browser was unable to establish a connection.
    * Could the site be temporarily unavailable? Try again later.
    * Are you unable to browse other sites? Check the computer's network connection.
    * Is your computer or network protected by a firewall or proxy? Incorrect settings can interfere with Web browsing.
    I can set the port. Just can't talk to it.

  • Corrupt Time Portion of a DATE column - how can this happen?

    DUMP(START_TIME)
    gives
    'Typ=12 Len=7: 100,99,255,255,0,0,0'
    How can this happen? Is there any way to prevent the database from allowing invalid dates to be inserted.
    Thanks in advance,
    Cade

    That's part of the problem. We don't have direct access to the database. I don't know what the equivalent of SQL Server's Query Analyzer or SSMS in Oracle. I'm more of a 'NET and SQL Server developer.
    What the group I am helping does is extract the data (from a system they don't control) using Focus. They send a SQL statement and then Focus retrieves the rowset and does what Focus calls a TABLE FILE operation to put it in a Focus file. Because the Focus rowset typing appears to be based on what datatypes Oracle represents the columns as having, Focus then attempts to interpret the date and time as valid. But apparently they are so messed up that Focus actually halts/crashes.
    So every morning, they notify the group responsible for the Oracle system to "fix" the records that are bad. They apparently do this by copying the END_TIME to the START_TIME, hopefully with a simple UPDATE query, but perhaps manually with some other tool.
    I'm also not a Focus expert, but in experimenting with sending different SQL statements (like using to_char() to identify the bad data) we did eventually find out how to identify these records using DUMP. What I helped the MIS group here do was to change their SQL query to be:
    SELECT CASE WHEN DUMP(START_TIME) = 'Typ=12 Len=7: 100,99,255,255,0,0,0' THEN END_TIME ELSE START_TIME END AS START_TIME
    FROM etc.

  • How can get a database like ****.SQL file for test in sqlplus in oracle8i

    How can get a database like ****.SQL file for test in sqlplus in oracle8i,I am a beginner,thanks

    I'll give it a guess as to what it is you want but I'm afraid you'll have to give some more information to go on. I appreciate it's difficult for people who are beginners or who don't have English as their first language.
    Are you trying to run a SQL file? From SQL*plus you can do either of these:
    SQL> start my_file
    or
    SQL> @my_file
    N.B.: if th efile has a .sql extension you don't need to include it, but you do for any other file extension e.g.
    SQL> @myfile.run
    Here is the page Vijay referred to:
    Re: Physical storage Checks & adding disk on server. I hope you find it useful.
    You will more helpful links (including links to the Oracle on-line manuals at this page:
    Re: How to attach a java bean in forms6i
    good luck, APC

  • How can I extract the native SQL generated by TopLink?

    How can I extract the native SQL generated by TopLink?
    This is useful for example to use pagination, or pass the SQL to a stored procedure that may do many things, like using a cursor, or apply security.
    Pagination example where the SQL inside the inner parentheses are generated from Toplink, and the outer SQL is generic:
    select *
    from
    (select xx.*, rownum as rn
    from
    (select o.order_id, r.name, ...
    from placed_order o, restaurant r
    where o.restaurant_id = r.restaurant_id
    order by o.order_ext_id
    ) xx
    where rownum < 21)
    where rn > 10

    Alternatively, you can open your sessions.xml in the Mapping Workbench and for a specific session, you can Click the Login Tab and then the Options tab. Then select "Native SQL" and it will be outputted to the console (assuming that is where you outputing it).
    zb

  • It appears windows hacker has locked my hard drive as readonly how can this be disabled?

    It appears windows hacker has locked my hard drive as readonly how can this be disabled?

    Sorry about the delay; I have called Apple Care sr advisors and spent 3 over 200 hrs explaining the problems to which they always recommend I exchange the Mac with a new one. This is my 5th Mac mini in less than 2 months. Many of the problems are not directly related to windows issues however (in my uneducated opinion should not be happening)Here are the unexplained issues:
    1. The sr advisors have been remotely connected to the machine and each one said I was setup on a server;
    2. My uid has been replaced with a windows uid (s-18-0-0-1 or sim);
    3. All the root certificates seem to be either fraudulent or modified to allow access to root account from remote locations;
    4. Apache server is active;
    5. WebDAV is configured as well as SQL services;
    6. Every newly exchanged Mac mini has iLife uninstalled prior to any updates being installed;
    7. Mac updates have warning messages indicating they are not signed properly, "contact software manufacture for more information", apple has no answer to this;
    8. Although I have never claimed (nor do I ever want to be computer program literate), I have been plagued by the same issues on Windows PC, Linux and now OS X. My main purpose for needing a secure computer is to write a resume and find employment. In 3 years I have been unable to do either. My data is always Either locked after as read only or is accessible on a URL only.
    9. I know this one will only classify me as an insane maniac but It appears as though I am connected to the Internet via an ipv6 udp connection even though my ISP doesn't support ip6 and all GUIs indicate all connections are inactive. This is typical no matter geographical location ie:Denver, San Deigo, Seattle, Boise et al)

  • Pages 5.5.1: When opening a document created with Pages '09 (Version 4.0) with Pages 5.5.1 the page header and the page footer are deleted. How can this be prevented? Or is this a bug in Pages 5.5.1?

    Pages 5.5.1: When opening a document created with Pages '09 (Version 4.0) with Pages 5.5.1 the page header and the page footer are deleted. How can this be prevented? Or is this a bug in Pages 5.5.1?

    Same problem here (no graphics in header or footer) and the problem has been reported months ago. It is another bug/feature lost when Apple moves from 09 to the iCloud-compatible versions.  Complain to Apple, you may have better chance than me and they may finally listen to their users....

  • Has anyone encountered drastic shorter battery life both on iphone 5 and ipad since updating to iOS 6.1.2? How can this problem be solved?

    Dear all,
    I am new to this community even though I have been a Apple user for years, so please forgive me if this question is not in the right section.
    Has anyone encountered drastic shorter battery life both on iphone 5 and ipad since updating to iOS 6.1.2? I've always been happy with these two products until the update - now the battery life is considerably shorter which is extremely frustrating.
    How can this problem be solved? Is there any way to go back to the previous version?
    Thanks for your help.

    If you update using iTunes the phone is first wiped clean, then the new OS is installed, and finally the backup is restored. After this finishes if you sync your music should be restored. Music is not in the backup, because it is already on your computer and duplicating it would use up a lot of hard disk space.
    An OTA update just patches what has changed; it does not disturb content.

  • After closing out, FF will not restart, says it is already running forcing me to reboot. I have removed and re-installed FF and still get the same message when trying to open the internet using FF. How can this be fixed?

    When I close out Firefox, and return later to use the internet, I click on Firefox and it gives me a message stating that Firefox is already running and needs to be closed before restarting or reboot my system. This occurs every time Firefox is closed and attempt to re-start it,,, not only at times,,,, EVERY time.
    I have tried removing Firefox from my system and re-installing to fix this issue however,,, this did not work. After re-installing, I still get the same message when attempting to restart Firefox.
    I have also tried Ctrl, Alt, delete to open the task manager and find there is no task to close.
    I do not have any problems when using IE, I prefer to use Firefox as it is faster and crashes less than IE.
    I am very frustrated at having to reboot my system each time I want to use the internet.
    How can this problem be repaired?

    There are various causes for this error, see [[Firefox is already running but is not responding]] for details.

  • I have downloaded the most recent version of Iphoto and it no longer works period. I lost all photos, and the app crashes every time I try to open it. How can this be fixed?

    I have downloaded the most recent version of Iphoto and it no longer works period. I lost all photos, and the app crashes every time I try to open it. How can this be fixed?

    Post the first 50 lines only of the crash report
    Regards
    TD 

  • When I try to get on the internet thru safari at home, on my network, I get a pop up that says Safari cannot open the page because it is not connected to the Internet.  How can this be and how do I fix it?

    when I try to get on the internet thru safari at home, on my network, I get a pop up that says Safari cannot open the page because it is not connected to the Internet.  How can this be and how do I fix it?

    Does the iPod connect to other networks?
    Do other device connect?
    Did the iPod connect to this network before?
    Try:
    - Reset the iPod. Nothing will be lost
    Reset iPod touch: Hold down the On/Off button and the Home button at the same time for at
    least ten seconds, until the Apple logo appears.
    - Power off and then back on the router
    - Reset network settings: Settings>GeneralReset>Reset Network Settings
    - iOS: Troubleshooting Wi-Fi networks and connections
    - iOS: Recommended settings for Wi-Fi routers and access points
    - Restore from backup
    - Restore to factory settings/new iPod.
    - Make an appointment at the Genius Bar of an Apple store.
    Apple Retail Store - Genius Bar

  • My husband and I share an ITunes account. He gets my apps and I get his. How can this be separated. I am also getting his contacts. My Icloud is turned off!

    My husband and I share an I tunes account.
    This was never a problem until I Cloud was born.
    I have turned off the Icloud on my I phone4 all together.
    He has Iphone 4S and is getting all the apps I purchase and I am getting his contacts.
    How can this be solved. If I get my own Itunes account do I have to purchase my apps again?
    Help!

    If you use another iTunes ID you can keep your apps, but you need to do some settings first.
    Read the hlep infos.
    http://support.apple.com/kb/HT4895
    I have purchased music, apps, or books with multiple Apple IDs. How can I get all of this content onto my iOS device?

    First, you need to copy all of your purchased content so it is on the same Mac or PC with iTunes. This computer should be the one you sync your device with. For more information on how to move your content, see these articles:
    Mac:  iTunes for Mac: How to copy purchases between computers
    PC:  iTunes for Windows: How to copy purchases between computers
    Next, authorize your computer to play content with each Apple ID in iTunes. Once your computer is authorized for all your content, it can be synced to your iPhone, iPad, or iPod touch. 
    And about the iCloud, I'm not very sure about that. I think maybe you don't need to turn off all of the iCloud settings, just the items you don't want to sync with your husband. For the apps, you can cancel 'automatically download purchased items' in the settings on iOS devices.
    May these informations will help you.
    JHinSel

  • I would like to transfer the balance from one Apple ID to another how can this be done??

    I want to transfer the account ballance from my account to my son's. I unintentionally redeemed one of his gift cards to my account. how can this be done?

    Sorry, but balances can't be transferred from one iTunes Store account to another. You'll either have to make his purchases through your account, or buy another prepaid card and redeem that in his account.
    BTW, for future questions, this forum is for questions from those managing sites on iTunes U, Apple's service for colleges and universities to post educational material in the iTunes Store. You'll be most likely to get help if you ask in the general iTunes forums.
    Regards.

Maybe you are looking for

  • What's wrong  with the role?

    I create URL iviews and pages, preview , it is OK. Then I create workset, role, and assign to a user. When I login with the account, I can't see the pages. Anybody help?

  • Long Text Missing In COA(Certificate of Analysis) Report

    Hi Friends, We have a case where Long text entered in the results recording is missing  in the COA Report for only certain Batches . For same MICs and COA Profile,the Long text is displayed correctly in the report for the different batches. I have in

  • Skype on Panasonic TV and MSN account

    Hi, I've a TV TX-L32ET5E and i can only connect with skype Id. Wwhen did Skype for TV update so that we can connect with MSN Id ?

  • Error: can't fetch data for this host - too few bytes supplied by RPC

    Hi, In our internal Lab we have: One Admin, Media,Client Server (we can make backups for himself) - Solaris 10 with DDS4 tape drive (lab) One Windows Client (we can make backups) - Windows XP One Linux Client - CentOS 5.1 When we add the linux client

  • FBCJ TRANSACTION

    Hi all, I´m working with the tcode FBCJ, is it any FM for consulting the actual amount if giving date, company code and cash journal number, I need to find that amount to show it in a special report i´m writing. Anybody knows? Thanks!! Gabriel P.