WRITING A GENERAL qUERY

Hi
I want to write a query which takes a argument such as a number n.
The query is used to get any nth largest number from a table.
I could write it for only one say getting the second largest number. I wrote it as:
A= Select * from Emp where sal !=(select max(sal) from Emp);
select max(sal) from A;
It is very complex to make this query a General one.
Can any body suggest an idea.
thanks

select ename, sal from (select row_number() over (order by sal desc) r, ename, sal from emp) where r=&n;
Enter value for n: 5
ENAME SAL
BLAKE 2850
Please read the documentation about the differences between rank(), dense_rank() and rownumber()
Regards
Laurent Schneider
OCM DBA

Similar Messages

  • General Query to identify parent columns and child columns in a table

    Does anyone know a general query that can be run to identify the child records associated with the parent column within a single table.....and between other tables?
    Am I correct in assuming the parent column is the 'primary key'?
    Thanks.....I'm a new to oracle...and need some help understanding
    my company's crazy DB structure

    You can use
    User_Constraints
    User_Cons_Columns
    views to identify parent and child table columns
    SELECT * FROM User_Constraints WHERE Constraint_Type = 'R' AND Table_Name = '<TABLENAME>';
    SELECT * FROM User_Cons_columns WHERE Constraint_Name = '<Name from Above query>';
    will give you columns of the parent table (if you use value from constraint_name) and of child table (if you use value from r_constraint_name).
    HTH..

  • General Query in OSB - 10gR3

    Hi,
    I have a general query in OSB. Whenever I try to add any expression through any message processing controls, there are three other tabs, comments, namespaces and variables. Can someone explain what is the use of namespaces and variables. If possible with the help of an example.
    Thanks,
    Bals

    Hi Bals,
    Comments allow the developer to put some lines regarding the functionality of that action/stage. This is same as putting comment in any programming language.
    XML Namespaces provide a method to avoid element name conflicts in a XML. To know more please refer -
    http://www.w3schools.com/xml/xml_namespaces.asp
    Variables section refers to the message context variables like $header, $body, $inbound, $outbound etc. You may refer below link to know more -
    http://download.oracle.com/docs/cd/E13159_01/osb/docs10gr3/userguide/context.html
    Regards,
    Anuj

  • Need help in writing SP notification Query

    Hi,
    My purpose of writing a query is to restrict a user to add journal entry in case account code lies in Expense Drawer and Cost Center Code is not in user define range.
    Please help me on this:-
    IF (@object_type = '30' AND (@transaction_type = 'A' Or @transaction_type = 'U'))
    BEGIN
    Declare @AccountCodeMaster as Nvarchar(20)
    Declare @AccountonDocument as Nvarchar(20)
    Declare @ProfitCentreMaster as Nvarchar(20)
    Declare @ProfitCentreOnDocument as Nvarchar(20)
    Set @AccountCodeMaster = (select AcctCode from oact where  GroupMask = 5)
    Set @AccountonDocument = (Select Account from jdt1 where TransId = @list_of_cols_val_tab_del)
    Set @ProfitCentreMaster = (select PrcCode from ocr1 where PrcCode >= 91100001 and PrcCode <= 91921001)
    Set @ProfitCentreOnDocument = (select ProfitCode from jdt1 where TransId = @list_of_cols_val_tab_del)
    if (@AccountonDocument) in (@AccountCodeMaster) and (@ProfitCentreOnDocument) not in (@ProfitCentreMaster)
    Begin
    set @error =1
    set @error_message = 'Profit Center is wrong,Please select the right profit Center else Consult to Finance Department'
    End
    END
    Thanks

    Hi,
    Welcome you post on the forum.
    You may try:
    IF (@object_type = '30' AND @transaction_type in ('A', 'U')
    BEGIN
    If Exists (Select T0.Account from jdt1 T0 inner join oact T1 ON T1.AcctCode=T0.Account AND T1.GroupMask = 5
    where T0.TransId = @list_of_cols_val_tab_del AND T0.ProfitCode NOT IN (select PrcCode from ocr1 where PrcCode >= 91100001 and PrcCode <= 91921001))
    Begin
    set @error =1
    set @error_message = 'Profit Center is wrong,Please select the right profit Center else Consult to Finance Department'
    End
    END
    Thanks,
    Gordon

  • HOWTO: Writing Out XML Query Results of Any Size in Java with XML SQL Utility

    A customer mailed me asking for an example of how to use our XML SQL Utility to write out query results for tons of query result rows.
    With tons of data, the getXMLDOM() and getXMLString() methods are not really appropriate due to the size.
    The XML SQL Utility offers a getXMLSAX() method that streams SAX2 events to report the data being queried. This is the approach we can use to handle data of any size.
    It dawned on me today that by putting together the XML SQL Utilities getXMLSAX() routine, and the oracle.xml.parser.v2.XSLSAXPrintDriver SAX2 ContentHandler, we can effectively stream out data of any length to an appropriate writer.
    Here's a code example to get the point across:
    package test;
    import java.io.BufferedOutputStream;
    import java.io.PrintWriter;
    import java.sql.Connection;
    import java.sql.Driver;
    import java.sql.DriverManager;
    import java.sql.SQLException;
    import java.util.Properties;
    import javax.xml.transform.OutputKeys;
    import oracle.jdbc.OracleDriver;
    import oracle.xml.parser.v2.XSLException;
    import oracle.xml.parser.v2.XSLOutput;
    import oracle.xml.parser.v2.XSLSAXPrintDriver;
    import oracle.xml.sql.query.OracleXMLQuery;
    public class Example  {
      private static final String QUERY = "select * from emp";
      public static void main(String[] args) throws Throwable  {
          Connection conn = getConnection();
          OracleXMLQuery q = new OracleXMLQuery(getConnection(),QUERY);
          // Any printwriter will do. Here's we're output to standard out.
          PrintWriter output = new PrintWriter(new BufferedOutputStream(System.out));
          // This is a SAX2 Content Handler used by the Oracle XSLT Engine
          // to serialize a stream of sax2 events as an XML document
          // We'll use it to serialize the sax2 events from the XML SQL Utility
          // out as an XML document.
          XSLSAXPrintDriver ch = new XSLSAXPrintDriver(output, outputOptions());  
          // This asks XML SQL Utility to fire sax events for the data
          // being fetched instead of creating DOM nodes or returning text.
          // By using the XSLSAXPrintDriver content handler, these events
          // get handled by writing them directly to the output stream
          q.getXMLSAX(ch);
          ch.flush();
          q.close();
          conn.close();     
      private static XSLOutput outputOptions() throws XSLException {
        XSLOutput x = new XSLOutput();
        Properties props = new Properties();
        props.put(OutputKeys.METHOD,"xml");
        props.put(OutputKeys.INDENT,"yes");  // Set to "no" for non-indented
        x.setProps(props);
        return x;
      public static Connection getConnection() throws SQLException {
        String username = "scott";
        String password = "tiger";
        String thinConn = "jdbc:oracle:thin:@localhost:1521:ORCL";
        Driver d = new OracleDriver();
        return DriverManager.getConnection(thinConn,username,password);
    }

    Hi Uber,
    This is a known issue that error occurs when running report "Count of instances of specific software registered with Add or Remove Programs" due to non-printable characters for XML. Based on internal research, the hotfix for this issue will be
    included in the System Center 2012 Configuration Manager Service Pack 1.
    As a workaround, you can remove the nonprintable character populated into the report parameter by referring to the following KB article:
    http://support.microsoft.com/KB/914159
    Hope this helps.
    Regards,
    Mike Yin
    Mike Yin
    TechNet Community Support

  • Frozen, white screen w/ black writing after general software update.

    I was trying to do a general software update on my MackBook Air when halfway through, the update stopped and a white screen popped up with the Apple in the middle and some black writing appeared in the upper left-hand corner. The writing is nothing that I recognize and looks like some kind fo code. The few things that make sense are " Unable to find driver for this platform" "BSD process name corresponding to current thread: Unknown" and "System update time in nanoseconds 347370409." I cannot do ANYTHING with the computer except turn it on and off and when I do that, the same screen comes up each time I turn it on. I cannot click on anything because no cursor appears. Please help! Thank you!

    Hi mary1490,
    Thanks for using Apple Support Communities.  I would recommend troubleshooting this as similar to a kernel panic.  This article has some steps that may help:
    OS X Mavericks: If your Mac restarts and a message appears
    http://support.apple.com/kb/PH14063
    Cheers,
    - Ari

  • Syntax error while writing a select query.

    Hi all,
    I have a requirement where I have to pick a value if the text for that value is
    MYCARu2019S Lovliest Car.
    And so I wrote a query that
    SELECT     RUECK INTO XRUECK FROM AFVC WHERE ltxa1 = ' MYCARu2019S Lovliest Car'.
                    ENDSELECT.
    But it gives me a syntax error saying     
    u201CLiterals taking up more than one line not permittedu201D.
    Can some one tell me what is wrong. I need to select RUECK value from AFVC  table if
    ltxa1 value is ' MYCARu2019S Lovliest Car'.
    Kindly help what is going wrong...
    Regards,
    Jessica Sam

    Hi,
    Narendran is right use two single quotes.
    also careful wile comparing string. i think as you write ltxa1 value is ' MYCARu2019S Lovliest Car'.
    so while comparing you must not use space just before staring use the following
    SELECT  rueck INTO xrueck FROM afvc WHERE ltxa1 = 'MYCAR''S Lovliest Car'. " Not use Space before M
    ENDSELECT.
    Hope will help you.
    Kind Regards,
    Faisal

  • Need help on performing database queries with a general query

    Dear experts,
    I have two issues
    1)
    I have developed a software which connects to Oracle database
    performing and executing DDL/DML statements.
    I am using a Jdbc thin oracle driver.
    When i perform a wrong syntax query or say a query using invalid column.I get exception accordingly.However,I want to know if there is any way by which i can know the exact position where i am making error
    just as an asterik(*) comes in sql plus in case of invalid column or so.
    2)
    Whenever i minimize software window (made of swing components)
    and again maximize it.It takes almost 12 secs to be visible otherwise it remains white.Is swing that much slow ???

    (1) No.
    (2) It's possible to make Swing programs that slow. (I know, I have done it.) But usually the slowness is in application code (your code) and not in Swing itself.

  • Need help in writing a select query to pull required data from 3 tables.

    Hi,
    I have three tables EmpIDs,EmpRoles and LatestRoles. I need to write a select Query to get roles of all employees present in EmpIDs table by referring EmpRoles and LatestRoles.
    The condition is first look into table EmpRoles and if it has more than one entry for a particular Employee ID than only need to get the Role from LatestRoles other wise consider
    the role from EmpRoles .
    Sample Script:
    Create Table #EmpIDs
    (EmplID int )
    Create Table #EmpRoles
    (EMPID int,Designation varchar(50))
    Create Table #LatestRoles
    EmpID int,
    Designation varchar(50)
    Insert into #EmpIDs values (1),(2),(3)
    Insert into #EmpRoles values (1,'Role1'),(2,'Role1'),(2,'Role2'),(3,'Role1')
    Insert into #LatestRoles values (2,'Role2')
    Employee ID 2 is having two roles defined in EmpRoles so for EmpID 2 need to fetch Role from LatestRoles table and for
    remaining ID's need to fetch from EmpRoles .
    My Final Output of select query should be like below.
    EmpID Role
    1 Role1
    2 Role2
    3 Role1
    Please help.
    Mohan

    Mohan,
    Can you check if this answers your requirement:
    Create Table #EmpIDs
    (EmplID int )
    Create Table #EmpRoles
    (EMPID int,Designation varchar(50))
    Create Table #LatestRoles
    EmpID int,
    Designation varchar(50)
    Insert into #EmpIDs values (1)
    Insert into #EmpIDs values (2)
    Insert into #EmpIDs values (3)
    Insert into #EmpRoles values (1,'Role1')
    Insert into #EmpRoles values (2,'Role2')
    Insert into #EmpRoles values (2,'Role1')
    Insert into #EmpRoles values (3,'Role1')
    Insert into #LatestRoles values (2,'Role2')
    --Method 1
    select e.EmplID,MIN(ISNULL(l.Designation,r.Designation)) as Designation
    from #empids e
    left join #emproles r on e.emplID=r.EmpID
    left join #latestRoles l on e.emplID=l.EmpID
    group by e.EmplID
    --Method 2
    ;with cte
    as
    select distinct e.EmplID,r.Designation,count(*) over(partition by e.emplID) cnt
    from #empids e
    left join #emproles r on e.emplID=r.EmpID
    select emplID,Designation
    from cte
    where cnt=1
    UNION ALL
    select a.EmplID,l.Designation
    from
    (select distinct EmplID from cte where cnt>1) a
    join #Latestroles l on a.EmplID=l.EmpID
    order by emplID
    Thanks,
    Jay
    <If the post was helpful mark as 'Helpful' and if the post answered your query, mark as 'Answered'>

  • Problem writing a sql query for a select list based on a static LOV

    Hi,
    I have the following table...
    VALIDATIONS
    ID          Number     (PK)
    APP_ID          Number     
    REQUESTED     Date          
    APPROVED     Date          
    VALID_TIL     Date
    DEPT_ID          Number     (FK)
    I have a search form with the following field item variables...
    P11_DEPT_ID (select list based on dynamic LOV from depts table)
    P11_VALID (select list based on static Yes/No LOV)
    A report on the columns of the Validations table is shown based on the values in the search form. So far, my sql query for the report is...
    SELECT v.APP_ID,
    v.REQUESTED,
    v.APPROVED,
    v.VALID_TIL,
    d.DEPT
    FROM DEPTS d, VALIDATIONS v
    WHERE d.DEPT_ID = v.DEPT_ID(+)
    AND (d.DEPT_ID = :P11_DEPT_ID OR :P11_DEPT_ID = -1)
    This query works so far. My problem is that I don't know how to do a search based on the P11_VALID item - if 'yes' is selected, then the VALID_TIL date is still valid. If 'no' is selected then the VALID_TIL date has passed.
    Can anyone help me to extend my query to include this situation?
    Thanks.

    Hello !
    Let's have a look at my example:create table test
    id        number
    ,valid_til date
    insert into test values( 1, sysdate-3 );
    insert into test values( 2, sysdate-2 );
    insert into test values( 3, sysdate-1 );
    insert into test values( 4, sysdate );
    insert into test values( 5, sysdate+1 );
    insert into test values( 6, sysdate+2 );
    commit;
    select * from test;
    def til=yes
    select *
      from test
      where decode(sign(trunc(valid_til)-trunc(sysdate)),1,1,0,1,-1)
           =decode('&til','yes',1,-1);
    def til=no
    select *                                                                               
      from test                                                                            
      where decode(sign(trunc(valid_til)-trunc(sysdate)),1,1,0,1,-1)
           =decode('&til','yes',1,-1);  
    drop table test;  It's working fine, I've tested it.
    The above changes to my first idea I did because of time portion of the DATE datatype in Oracle and therefore the wrong result for today.
    For understandings:
    1.) TRUNC removes the time part of DATE
    2.) The difference of to date-values is the number of days between.
    3.) SIGN is the mathematical function and gives -1,0 or +1 according to an negative, zero or positiv argument.
    4.) DECODE is like an IF.
    Inspect your LOV for the returning values. According to my example they shoul be 'yes' and 'no'. If your values are different, you may have to modify the DECODE.
    Good luck,
    Heinz

  • Help needed on writing a SQL query

    Here is my table that shows records of 3 ORDER_ID (10, 20 and 30). All I need to do is, pick the first record of each order_id and check the event_id, if the event_id is same for the next record, ignore it, else show it and ignore rest all records for that order_id. This way my query output will show only two records for each ORDER_ID. Query should produce records that are in BOLD in the sample data. (Database - 11g)
    Thanks for your help in advance
    ORDER_ID     EVENT_ID     EVNT_DATE     STATE_CODE
    *10     16937555     20100212     COMPLETE*
    10     16937555     20100212     ACTIVE
    *10     16308004     20100129     OCCURRED*
    10     16131904     20100125     ACTIVE
    10     16270684     20100128     OCCURRED
    10     14899116     20091213     ACTIVE
    10     16085672     20100123     COMPLETE
    10     16085673     20100123     OCCURRED
    10     14899119     20100123     COMPLETE
    10     14899120     20100123     COMPLETE
    *20     17134164     20100223     COMPLETE*
    20     17134164     20100223     ACTIVE
    20     17134164     20100223     STARTED
    *20     15479131     20100105     OCCURRED*
    20     15478409     20100105     OCCURRED
    20     15478408     20100105     ACTIVE
    20     15119404     20100105     COMPLETE
    20     14346123     20091129     ACTIVE
    20     15467821     20100104     OCCURRED
    20     14346125     20091216     COMPLETE
    20     14346126     20091215     COMPLETE
    20     14346126     20091214     COMPLETE
    *30     18814670     20100412     COMPLETE*
    30     18814670     20100412     ACTIVE
    *30     18029509     20100320     OCCURRED*
    30     16853720     20100211     ACTIVE
    30     17965764     20100319     OCCURRED
    30     16386708     20100211     COMPLETE
    30     16804451     20100211     OCCURRED
    30     15977897     20100121     ACTIVE
    Edited by: sarvan on Aug 12, 2011 7:16 AM

    try this [Not fully tested]
    SQL> select * from v$version;
    BANNER
    Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production
    PL/SQL Release 11.2.0.2.0 - Production
    CORE    11.2.0.2.0      Production
    TNS for Linux: Version 11.2.0.2.0 - Production
    NLSRTL Version 11.2.0.2.0 - Production
    Elapsed: 00:00:00.00
    SQL> SELECT *
      2    FROM (SELECT order_id, event_id, evnt_date, state_code, next_evntid,
      3                 ROW_NUMBER () OVER (PARTITION BY event_id ORDER BY NULL)
      4                                                                       AS rownm
      5            FROM (WITH t AS
      6                       (SELECT 10 AS order_id, 16937555 AS event_id,
      7                               20100212 AS evnt_date, 'COMPLETE' AS state_code
      8                          FROM DUAL
      9                        UNION ALL
    10                        SELECT 10, 16937555, 20100212, 'ACTIVE'
    11                          FROM DUAL
    12                        UNION ALL
    13                        SELECT 10, 16308004, 20100129, 'OCCURRED'
    14                          FROM DUAL
    15                        UNION ALL
    16                        SELECT 10, 16131904, 20100125, 'ACTIVE'
    17                          FROM DUAL
    18                        UNION ALL
    19                        SELECT 10, 16270684, 20100128, 'OCCURRED'
    20                          FROM DUAL
    21                        UNION ALL
    22                        SELECT 20, 17134164, 20100223, 'COMPLETE'
    23                          FROM DUAL
    24                        UNION ALL
    25                        SELECT 20, 17134164, 20100223, 'ACTIVE'
    26                          FROM DUAL
    27                        UNION ALL
    28                        SELECT 20, 17134164, 20100223, 'STARTED'
    29                          FROM DUAL
    30                        UNION ALL
    31                        SELECT 20, 15479131, 20100105, 'OCCURRED'
    32                          FROM DUAL)  -- End of test data
    33                  SELECT order_id, event_id, evnt_date, state_code,
    34                         LEAD (event_id, 1, 0) OVER (PARTITION BY order_id ORDER BY NULL)
    35                                                                 AS next_evntid
    36                    FROM t)
    37           WHERE event_id = next_evntid)
    38   WHERE rownm <= 2
    39  /
      ORDER_ID   EVENT_ID  EVNT_DATE STATE_CO NEXT_EVNTID      ROWNM
            10   16937555   20100212 COMPLETE    16937555          1
            20   17134164   20100223 COMPLETE    17134164          1
            20   17134164   20100223 ACTIVE      17134164          2
    Elapsed: 00:00:00.00
    SQL> PS - You should seriously think about ordering the data before you do this kind off operations.
    Edited by: Sri on Aug 12, 2011 9:12 AM

  • Idoc to file scenario general query

    Hi All,
    I know about the basic settings needed for the Idoc to file scenario.
    My query is related the idoc /ALE settings.
    I have a scenatio wrking in my system where we have configured the port for B type partner and also the port as XML-HTTP
    I can not see any DM(BD64) created for it basically.I want to know that in what scenarios the BD64 configuration is required.
    Or it is the case that if we define the BD64 then we do not need to configure we20 and we21, it will be auto configured?
    Please let me know the use cases for these different configurations if any.
    Thanks in advance.
    Regards,
    Rahul Kulkarni

    Hi Rahul,
    BD64 uses mostly IDoc to IDoc scenarios because the IDoc consults the distribution model and determines whether any filter objects are specified for a receiver.
    WE20 and WE21 (Partner Profile,Port Definition) we have to define in any scenarios where ECC included.
    Thanks,
    Seshu.

  • General query regarding the implementation of a Flash Streaming Server

    Hey lads,
    I'm looking at setting up an Adobe Flash Streaming Server at
    work. It will be used primarily to stream training videos across
    our Intranet - we have ~1000 users at the moment, with the capacity
    to expand to ~2000). We are looking at both filming with a camera
    and screencasting (using either
    Camtasia or Adobe
    Captivate) and then encoding to .FLV
    Camtasia can encode directly to FLV, however I'm not too sure
    of the quality, so the Adobe Flash Media Live Encoder looks like a
    good option too. For the time being we will just be concentrating
    on the screencasting though.
    The good thing is i can download a development server for
    free from Adobe which gives me complete access with just a
    restriction on the amount of users that can access the content
    (10).
    From what i can gather the (simple) way it works (and that
    I want it to work) is that you have a standard template SWF
    file containing relevant actionscript (sitting in most probably in
    a html/php/asp/ect file on the webserver), which then calls the FLV
    file from the flash server and streams the content to the clients
    PC. I assume i will pass a variable to the SWF file (the video ID i
    want), and that will then be used to call the corresponding FLV
    file.
    So effectively a YouTube website, i.e:
    watch?
    v=WjK6wNIWzts
    I just wanted to know if anyone had any general tips on how i
    should approach this? Obviously quality vs file size will be a big
    point - deciding on a standard FLV format will be a mission,
    however i do have the benefit of an internal network so can anyone
    recommend some good encoding tips? I was actually thinking of
    encoding a low quality and high quality version, but i don't think
    that's really sustainable/effective.
    There is a bit of documentation around for this, but they
    tend not to answer the basic questions. Am i heading in the right
    direction?
    Thanks for your help :)

    If you are not able to find older version of connector on Metalink then raise an SR with Oracle and give proper Business Justification for the same.

  • Problem writing a sql query

    I am a Java Developer and new to database.
    Database Table:
    Table 'Authors' with fields 'Author'(Varchar2), 'Code'(Varchar2), 'Id'(Varchar2 ~ Not a primary key, multiple records can have same value) and 'Date_Sequence'(Number). The possible values for 'Code' could be either 'Yes' or 'No'.
    Approach:
    I can select a list of authors, say AYES AUTHORS with code 'Yes' and a list of authors, say NOES AUTHORS with code 'No' from my web page.
    When I submit the request, I need to retrieve all the Id's, where AYES Authors voted 'Yes' and NOES Authors voted 'No'.
    I have come up with the following query:
    SELECT DISTINCT ID FROM AUTHORS WHERE AUTHOR IN ('my selected AYES list') AND CODE = 'Yes'
    INTERSECT
    SELECT DISTINCT ID FROM AUTHORS WHERE AUTHOR IN ('my selected NOES list') AND CODE = 'No'
    Problem:
    Now the problem here being, I have to retrieve the id's where the 'Date Sequence' is same for 'Yes' and 'No'. Not sure how to link the Date_Sequence for both the queries across the intersect clause. Any clue is highly appreciated.
    Thanks.

    Not sure if i understand what the logic behind it is, but try this..
    WITH AUTHORS AS (SELECT 'AYES1' AUTHOR, 'Yes' CODE, '1' ID, TRUNC(SYSDATE) DATE_SEQ FROM DUAL
                     UNION ALL
                     SELECT 'AYES2' AUTHOR, 'Yes' CODE, '2' ID, TRUNC(SYSDATE)-1 DATE_SEQ FROM DUAL
                     UNION ALL
                     SELECT 'AYES3' AUTHOR, 'No'  CODE, '3' ID, TRUNC(SYSDATE) DATE_SEQ FROM DUAL
                     UNION ALL
                     SELECT 'NOES1' AUTHOR, 'No' CODE, '1' ID,  TRUNC(SYSDATE) DATE_SEQ FROM DUAL
                     UNION ALL
                     SELECT 'NOES2' AUTHOR, 'No'  CODE, '2' ID, TRUNC(SYSDATE) DATE_SEQ FROM DUAL
    SELECT AYES.ID, AYES.DATE_SEQ
      FROM AUTHORS AYES,
           AUTHORS NOES
    WHERE AYES.AUTHOR IN ('AYES1', 'AYES2', 'AYES3') AND AYES.CODE='Yes'
       AND NOES.AUTHOR IN ('NOES1', 'NOES2', 'NOES3') AND NOES.CODE='No'
       AND AYES.ID=NOES.ID
       AND AYES.DATE_SEQ=NOES.DATE_SEQ
    ID         DATE_SEQ
    1          22.10.08
    SQL>

  • Please help me in writing a simple query....

    Hi,
    I want a single query to retrieve the data as shown below.....
    i have two tables
    master(id primary key, name);
    child( childid primary key, name, id)
    here id referes the master(id)
    let us say the data in the two tables like
    master
    id name
    1 master1
    2 master2
    3 master3
    child
    childid name id
    1 child1 1
    2 child2 1
    3 child3 2
    4 child4 3
    5 child5 3
    6 child6 3
    Now the result i want is like
    id name parentid
    1 master1 0
    1 child1 1
    2 child2 1
    2 master2 0
    3 child3 2
    3 master3 0
    4 child4 3
    5 child5 3
    6 child6 3
    thanks in advance,
    regards,
    khaleel

    SELECT   master.id,
             master.name,
             0 AS parentid,
             master.name AS mastername,
             NULL AS childname,
             'parent' AS type
    FROM     master
    UNION 
    SELECT   child.childid AS id,
             child.name,
             child.id AS parentid,
             master.name AS mastername,
             child.name AS childname,
             'child' AS type
    FROM     child,
             master
    WHERE    child.id = master.id
    ORDER BY mastername,
             type DESC,
             childname
            ID NAME         PARENTID MASTERNAME CHILDNAME  TYPE
             1 master1             0 master1               parent
             1 child1              1 master1    child1     child
             2 child2              1 master1    child2     child
             2 master2             0 master2               parent
             3 child3              2 master2    child3     child
             3 master3             0 master3               parent
             4 child4              3 master3    child4     child
             5 child5              3 master3    child5     child
             6 child6              3 master3    child6     child
    9 rows selected.

Maybe you are looking for

  • Kmail web links broken after pacman -Syu

    Hello - I use Kontact/Kmail for my email. After a recent upgrade, web links no longer work in my emails. When I click on any type of link in an email, an "infinite loop" of processes is generated. No windows appear, just process after process is star

  • How to change the network name and line name on iPad 4?

    Could anybody help me how to fix this problem? Previously I used qb (a mobile network in Cambodia) for my iPad 4 (iOS 7.0.4 non-jailbreak) the network name is qb. The problem is that after I changed to use SMART (another mobile network in Cambodia) f

  • Laptop to TV HDMI problem

    I am trying to hook up my MBP to my 32" Philips TV (I have all the right equipment), but when I hook it all up nothing happens. I click on scan for displays and it nevers finds any other displays. does anybody know how to solve this problem?

  • IPhoto 11 - Problem viewing shared photos

    Hi, We have two MBP and we're having trouble viewing the photos from the other library via the Share function. The share is occurring through FW. Both MBP are running iPhoto 9.1.3. The issue is that MBP A can see MBP B's photos through share, but MBP

  • Partially corrupt iPhoto Library

    I am using iPhoto 6.0.6 Recently, some of my older Rolls have had their photos seemingly disappear. They are actually moved under a folder ~iPhoto Library/Originals/2009/SomeNewRoll. This folder has 2400 photos in it, but the corresponding roll, Some