Guide me to write a query

Hi All,
I want to retrieve some 7 fields from 3 tables
5 from prd_common_info
1 from vendor
1 from srv_act
common column :
prd_common_info and srv_act - prd_code
srv_act and vendor - vendor_id
vendor and prd_common_info - LAST_MOD_USER
condition should be PRD_CODE = 'M-DATA' and INV_STATUS_FLAG='A'
I have written a query beloe.but the problem here all the data is getting duplicated(too many records for one entry).
SELECT P.PRD_CODE,P.CIRCUIT_ID,P.NAME,P.EMP_ID,P.END_USER_EMAIL,V.VENDOR_NAME,P.COMMENTS
FROM
PRD_COMMON_INFO P,SRV_ACT S,VENDOR V
WHERE P.PRD_CODE = 'M-DATA' and INV_STATUS_FLAG='A'
AND P.PRD_CODE=S.PRD_CODE and S.VENDOR_ID=V.VENDOR_ID AND V.LAST_MOD_USER=P.LAST_MOD_USER
Please help me to write the query.
Regards,
Saji

Hi,
If the problem in duplicate records only, use DISTINCT
SELECT DISTINCT P.PRD_CODE,
                P.CIRCUIT_ID,
                P.NAME,
                P.EMP_ID,
                P.END_USER_EMAIL,
                V.VENDOR_NAME,
                P.COMMENTS
  FROM PRD_COMMON_INFO P, SRV_ACT S, VENDOR V
WHERE     P.PRD_CODE = 'M-DATA'
       AND INV_STATUS_FLAG = 'A'
       AND P.PRD_CODE = S.PRD_CODE
       AND S.VENDOR_ID = V.VENDOR_ID
       AND V.LAST_MOD_USER = P.LAST_MOD_USERSaad,

Similar Messages

  • How to write named query if we want to use IN syntax in our sql statement?

    I cannot find a suitable category about named query, so please move to appropriate place if there is any.
    When we write named query, below statement is fine.
    Query q2 = em.createQuery("SELECT o FROM Table1 as o WHERE field1 = :input1");             q2.setParameter("input1", "value1");
    Now, my question is, how can I write this type of query when we want to use the IN sql syntax? As below statement CANNOT return correct results. Even I tried to put a pair of single quote [ ':input2' ], it won't help also.
    Query q2 = em.createQuery("SELECT o FROM Table1 as o WHERE field2 IN (:input2)");             q2.setParameter("input1", "3633, 3644");
    Can anyone suggest? Thanks.

    roamer wrote:
    Now, my question is, how can I write this type of query when we want to use the IN sql syntax? As below statement CANNOT return correct results. Even I tried to put a pair of single quote [ ':input2' ], it won't help also.
    Query q2 = em.createQuery("SELECT o FROM Table1 as o WHERE field2 IN (:input2)");
    q2.setParameter("input1", "3633, 3644");
    Can anyone suggest?The above is in your code right? Not in some configuration file?
    Then you do it the same way as with regular jdbc/sql.
    1. You start with a collection of values - call it collection A.
    1. Create a for loop that dynamically creates the string using 'bind' variables (whatever you want to call the 'colon' entity in the above).
    2. Call the createQuery method using the string that was created
    3. Create a second loop that iterates over A and populates with setParameter.
    Pseudo code
            Object[] A = ...
            String sql = "SELECT o FROM Table1 as o WHERE field2 IN (";
            for (int i=1; i <= A.length; i++)
                  if (i == 1)
                     sql += ":input" + i;
                 else
                     sql += ",:input" + i;
            sql += ")";
            Query q2 = em.createQuery(sql);
            for (int i=1; i <= A.length; i++
                  q2.setParameter("input" + i, A[i-1]);
                  }By the way there is a jdbc forum.

  • A better way to write last_day query

    Hi folks,
    I am looking for a better way to write a query to find last_day in month but if its sunday or holiday it should move to day before last day.
    So for example if 31 is sunday it should go for 30, if 30 is holiday it should move down to 29.
    I got this so far but the connect by level is hardcoded to 15. Want to see if there is a better way to get this working:
    select max(datum)
      from (    select last_day(trunc(sysdate)) - level + 1 as datum
                  from dual
            connect by level < 15)
    where to_char(datum, 'day') != 'sunday'    
       and to_char(datum, 'DDMM') not in
             ('3012')Best regards,
    Igor

    Like this
    select to_char(last_day_month, 'Day') day_is,
           last_day_month,
           last_day_month - case when to_char(last_day_month, 'fmday') = 'sunday' then 1
                                 when to_char(last_day_month, 'ddmm' ) = '3012'   then 1
                                 else 0
                            end last_business_day_month
      from (
              select last_day(add_months(trunc(sysdate, 'year'), level-1)) last_day_month
                from dual
              connect by level <= 12
    DAY_IS    LAST_DAY_MONTH LAST_BUSINESS_DAY_MONTH
    Tuesday   31-JAN-12      31-JAN-12              
    Wednesday 29-FEB-12      29-FEB-12              
    Saturday  31-MAR-12      31-MAR-12              
    Monday    30-APR-12      30-APR-12              
    Thursday  31-MAY-12      31-MAY-12              
    Saturday  30-JUN-12      30-JUN-12              
    Tuesday   31-JUL-12      31-JUL-12              
    Friday    31-AUG-12      31-AUG-12              
    Sunday    30-SEP-12      29-SEP-12              
    Wednesday 31-OCT-12      31-OCT-12              
    Friday    30-NOV-12      30-NOV-12              
    Monday    31-DEC-12      31-DEC-12 

  • Crystal Report XI: Can you write your query in SQL instead of using the GUI

    Hello
      In crystal report version XI, can you write your query in sqlplus and then use the crystal report designer to build your report instead of using the GUI . I would like to be able to go database and show sql query and open that query and make changes directly there, is that possible on this version, if yes is there a setting somewhere? Please let me know.
    Thank you
    alpha

    Moved to Database forum.
    No you can no longer modify the SQL directly. Use a Command Object to enter the SQL directly.
    Thank you
    Don

  • Please help to re-write this query using exists or with

    Hi please help to re-write this query using exists or with, i need to write same code for 45 day , 90 days and so on but sub query condition is same for all
    SELECT SUM (DECODE (t_one_mon_c_paid_us, 0, 0, 1)) t_two_y_m_mul_ca_
    FROM (SELECT SUM (one_mon_c_paid_us) t_one_mon_c_paid_us
    FROM (
    SELECT a.individual_id individual_id,
    CASE
    WHEN NVL
    (b.ship_dt,
    TO_DATE ('05-MAY-1955')
    ) >= SYSDATE - 45
    AND a.country_cd = 'US'
    AND b.individual_id in (
    SELECT UNIQUE c.individual_id
    FROM order c
    WHERE c.prod_cd = 'A'
    AND NVL (c.last_payment_dt,
    TO_DATE ('05-MAY-1955')
    ) >= SYSDATE - 745)
    THEN 1
    ELSE 0
    END AS one_mon_c_paid_us
    FROM items b, addr a, product d
    WHERE b.prod_id = d.prod_id
    AND d.affinity_1_cd = 'ADH'
    AND b.individual_id = a.individual_id)
    GROUP BY individual_id)
    Edited by: user4522368 on Aug 23, 2010 9:11 AM

    Please try and place \ before and after you code \Could you not remove the inline column select with the following?
    SELECT a.individual_id individual_id
         ,CASE
            when b.Ship_dt is null then
              3
            WHEN b.ship_dt >= SYSDATE - 90
              3
            WHEN b.ship_dt >= SYSDATE - 45
              2
            WHEN b.ship_dt >= SYSDATE - 30
              1
          END AS one_mon_c_paid_us
    FROM  items           b
         ,addr            a
         ,product         d
         ,order           o
    WHERE b.prod_id       = d.prod_id
    AND   d.affinity_1_cd = 'ADH'
    AND   b.individual_id = a.individual_id
    AND   b.Individual_ID = o.Individual_ID
    and   o.Prod_CD       = 'A'             
    and   NVL (o.last_payment_dt,TO_DATE ('05-MAY-1955') ) >= SYSDATE - 745
    and   a.Country_CD    = 'US'

  • How to write a query for grouping them the columns and give the sequence order to each group/

    Hi i have table that contains country columns .
    India,USA,UK like these when ever the group changed into the differt country i make a group and arrange them the sequence into those Countries
    like below
    1)India
    2)India
    1)USA
    2)USA
    like these to write a query ..........pls help me for this query

    Assuming you're using SQL Server you can ask here:
    http://www.sqlteam.com/forums/forum.asp?FORUM_ID=23
    Otherwise, please ask in the relevant forum for the type of technology you're using.
    Basically it's either:
    select *
    from [table name]
    order by country
    If you want to do something with groups do something like:
    select (max) income, country
    from [table name]
    group by country
    Kind regards,
    Margriet Bruggeman
    Lois & Clark IT Services
    web site: http://www.loisandclark.eu
    blog: http://www.sharepointdragons.com

  • Write a query

    how to write a sql query to find names of employees who have promoted to junior accountant to accountant using exists operator in oracle.
    My table is an employee table

    <FONT FACE="Arial" size=2 color="2D0000">
    how to write a sql query to find names of employees
    who have promoted to junior accountant to accountant
    using exists operator in oracle.
    My table is an employee tablesql query post
    we are not magicians to see your employee table..
    Do not order us to write a query for you....
    pls post your work around.
    </FONT>

  • How to write sql query with many parameter in ireport

    hai,
    i'm a new user in ireport.how to write sql query with many parameters in ireport's report query?i already know to create a parameter like(select * from payment where entity=$P{entity}.
    but i don't know to create query if more than 1 parameter.i also have parameter such as
    $P{entity},$P{id},$P{ic}.please help me for this.
    thanks

    You are in the wrong place. The ireport support forum may be found here
    http://www.jasperforge.org/index.php?option=com_joomlaboard&Itemid=215&func=showcat&catid=9

  • I need to add a single field from with_item table . need to write select query with reference to company code , account doc no , fiscal year

    I need to add a single field from with_item table . need to write select query with reference to company code , account doc no , fiscal year

    Hi Arun ,
    Can you explain little bit more ??
    what is account doc no? 
    what are the transactions should be displayed in your output??
    -Rajesh N

  • How to write this query to filter combination of few values

    Hi,
    I have a table CHIMM which is a transaction table and contains information of the vaccines given to a child.
    columns are: child_id, vacc_id, vacc_given_dt. I have to query for remaining vaccines.
    HEXA is a vaccine_id which is composite vaccine of DPT1,POL1,HBV1 & HIB1 (vaccine ids).
    I want to write to query if any of DPT1,POL1,HBV1 & HIB1 given then HEXA should not be displayed in the result.
    OR
    if HEXA is given then of course any of DPT1,POL1,HBV1 & HIB1 should not be displayed in the result.
    How to write this query?
    Regards

    Hi,
    I'm still not sure what the output you want from that sample data is. Do you just want the child_ids, like this
    CHILD_ID
           3
           4? If so, here's one way to get them:
    WITH     all_vacc_ids     AS
         SELECT     c.child_id
         ,     c.vacc_id          AS child_vacc_id
         ,     v.vacc_id
         ,     COUNT ( CASE
                             WHEN  c.vacc_id = 'HEXA'
                       THEN  1
                         END
                    )       OVER ( PARTITION BY  c.child_id
                                       )    AS hexa_itself
         FROM          vacc   v
         LEFT OUTER JOIN     chimm  c     PARTITION BY (c.child_id)
                          ON     c.vacc_id     = v.vacc_id
         WHERE   v.vacc_desc       = 'HEXA'     -- See note below
    SELECT       child_id
    FROM       all_vacc_ids
    WHERE       child_vacc_id     IS NULL
      AND       vacc_id     != 'HEXA'
      AND       hexa_itself     = 0
    GROUP BY  child_id
    rha2 wrote:there are alot of vaccines, i just put 3 for example. this query gives error: invalid relational operatorAre you saying that the vacc table contains other rows, but those other rows are not needed for this problem? It would be good if you included an example in the sample data. The query above considers only the rows in vacc where vacc_desc='HEXA'. You can have other rows in the vacc table, but they won't affect the output of this query. The query above makes no assumptions about the number of rows that have vacc_desc='HEXA'; it will report all child_ids who are missing any of them, regardless of the number (assuming the child does not have the 'HEXA' vacc_id itself, like child_id=1).
    You still haven't said which version of Oracle you're using. The query above will work in Oracle 10 (and higher).

  • How to write this query ?

    how to write this query ?
    list the emp name who is working for the highest avg sal department.
    I can use row_number over to get correct result. If we don't use this row_number function, just plain sql, how to do it ?
    the row_number version is like this
    select emp.* from emp ,
    select deptno, row_number() over (order by avg(sal) desc) r from emp
    group by deptno
    )e
    where e.r = 1
    and emp.deptno = e.deptno

    Hi,
    806540 wrote:
    how to write this query ?
    list the emp name who is working for the highest avg sal department.
    I can use row_number over to get correct result. If we don't use this row_number function, just plain sql, how to do it ?ROW_NUMBER is just plain SQL, and has been since Oracle 8.1.
    ROW_NUMBER (or its close relative, RANK) is the simplest and most efficient way to solve this problem. Why not do this the right way?
    the row_number version is like this
    select emp.* from emp ,
    select deptno, row_number() over (order by avg(sal) desc) r from emp
    group by deptno
    )e
    where e.r = 1
    and emp.deptno = e.deptno
    If there happens to be a tie (that is, two or more departments have the same average sal, and it is the highest), then the query above will only arbitrarily treat one of them (no telling which one) as the highest. Change ROW_NUMBER to RANK to get all departments with a claim to having the highest average sal.
    You could use the ROWNUM pseudo-column instead of ROW_NUMBER, if all you want to do is avoid ROW_NUMBER.
    Without using ROW_NUMBER or RANK, there are lots of ways involving other analytic functions, such as AVG and MAX.
    If you really, really don't want to use analytic functions at all, you can do this:
    SELECT     *
    FROM     scott.emp
    WHERE     deptno     IN  (
                      SELECT       deptno
                      FROM       scott.emp
                      GROUP BY  deptno
                      HAVING       AVG (sal) =  (
                                                       SELECT    MAX (AVG (sal))
                                               FROM          scott.emp
                                               GROUP BY  deptno
    ;

  • How to write complex query with jpa criteria builder.

    Hello,
    I want to write a query in jpa criteriaquery. Here is the query:
    SELECT node.category_name, (COUNT(parent.category_name) - 1) AS depth
    FROM category_subcategories AS node,
    category_subcategories AS parent
    WHERE node.lft BETWEEN parent.lft AND parent.rgt
    AND node.category_name = 'PORTABLE ELECTRONICS'
    GROUP BY node.category_name
    ORDER BY node.lft
    Here is the code I come up with:
    CriteriaBuilder cb = em.getCriteriaBuilder();
    CriteriaQuery<CategorySubcategories> cq = cb.createQuery( CategorySubcategories.class );
    Root<CategorySubcategories> node = cq.from( CategorySubcategories.class );
    Root<CategorySubcategories> parent = cq.from( CategorySubcategories.class );
    Predicate p1 = cb.equal(node.get("categoryName"), categoryName);
    Predicate p2 = cb.between(node.get("lft").as(Integer.class), parent.get("lft").as(Integer.class), parent.get("rgt").as(Integer.class));
    Order nodeLft = cb.asc(node.get("lft"));
    cq.multiselect(node.get("categoryName"), cb.count(parent.get("categoryName")))
    .where(p1, p2)
    .groupBy(node.get("categoryName"))
    .orderBy(nodeLft);
    return em.createQuery(cq).getResultList();
    When I execue the test, it shown the following error:
    Testcase: testDepthOfSubtree(au.com.houseware.server.ejb.entity.facade.CategorySubcategoriesFacadeTest): Caused an ERROR
    org.hibernate.hql.ast.QuerySyntaxException: Unable to locate appropriate constructor on class [au.com.houseware.server.ejb.entity.CategorySubcategories] [select new au.com.houseware.server.ejb.entity.CategorySubcategories(generatedAlias0.categoryName, count(generatedAlias1.categoryName)) from au.com.houseware.server.ejb.entity.CategorySubcategories as generatedAlias0, au.com.houseware.server.ejb.entity.CategorySubcategories as generatedAlias1 where ( generatedAlias0.categoryName=:param0 ) and ( generatedAlias0.lft between generatedAlias1.lft and generatedAlias1.rgt ) group by generatedAlias0.categoryName]
    java.lang.IllegalArgumentException: org.hibernate.hql.ast.QuerySyntaxException: Unable to locate appropriate constructor on class [au.com.houseware.server.ejb.entity.CategorySubcategories] [select new au.com.houseware.server.ejb.entity.CategorySubcategories(generatedAlias0.categoryName, count(generatedAlias1.categoryName)) from au.com.houseware.server.ejb.entity.CategorySubcategories as generatedAlias0, au.com.houseware.server.ejb.entity.CategorySubcategories as generatedAlias1 where ( generatedAlias0.categoryName=:param0 ) and ( generatedAlias0.lft between generatedAlias1.lft and generatedAlias1.rgt ) group by generatedAlias0.categoryName]
    at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1201)
    at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1147)
    at org.hibernate.ejb.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:324)
    at org.hibernate.ejb.criteria.CriteriaQueryCompiler.compile(CriteriaQueryCompiler.java:227)
    at org.hibernate.ejb.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:441)
    at au.com.houseware.server.ejb.entity.facade.CategorySubcategoriesFacadeMock.findDepthOfSubtreeBy_categoryName(CategorySubcategoriesFacadeMock.java:228)
    at au.com.houseware.server.ejb.entity.facade.CategorySubcategoriesFacadeTest.testDepthOfSubtree(CategorySubcategoriesFacadeTest.java:44)
    Caused by: org.hibernate.hql.ast.QuerySyntaxException: Unable to locate appropriate constructor on class [au.com.houseware.server.ejb.entity.CategorySubcategories] [select new au.com.houseware.server.ejb.entity.CategorySubcategories(generatedAlias0.categoryName, count(generatedAlias1.categoryName)) from au.com.houseware.server.ejb.entity.CategorySubcategories as generatedAlias0, au.com.houseware.server.ejb.entity.CategorySubcategories as generatedAlias1 where ( generatedAlias0.categoryName=:param0 ) and ( generatedAlias0.lft between generatedAlias1.lft and generatedAlias1.rgt ) group by generatedAlias0.categoryName]
    at org.hibernate.hql.ast.QuerySyntaxException.convert(QuerySyntaxException.java:54)
    at org.hibernate.hql.ast.QuerySyntaxException.convert(QuerySyntaxException.java:47)
    at org.hibernate.hql.ast.ErrorCounter.throwQueryException(ErrorCounter.java:82)
    at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:261)
    at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:185)
    at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:136)
    at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:101)
    at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:80)
    at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:124)
    at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:156)
    at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:135)
    at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1770)
    at org.hibernate.ejb.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:306)
    What is wrong with my criteriaQuery?
    Any suggestion is very much appreciated.
    Thanks
    Sam
    Edited by: 785102 on Mar 26, 2011 7:44 PM

    Hello,
    Thank you for your response.
    If I remove CategorySubcateogires, netbeans complained:
    incompatible types
    required: javax.persistence.criteria.CriteriaQuery<au.com.houseware.server.ejb.entity.CategorySubcategories>
    found: javax.persistence.criteria.CriteriaQuery<java.lang.Object>
    When I removed all CategorySubcategories type and replaced it with Object like this:
    public Collection<Object> findDepthOfSubtreeBy_categoryName(String categoryName) {
    CriteriaBuilder cb = em.getCriteriaBuilder();
    CriteriaQuery<Object> c = cb.createQuery();
    Root<CategorySubcategories> node = c.from( CategorySubcategories.class );
    Root<CategorySubcategories> parent = c.from( CategorySubcategories.class );
    Predicate p1 = cb.equal(node.get("categoryName"), categoryName);
    Order nodeLft = cb.asc(node.get("lft"));
    c.multiselect(node.get("categoryName"), cb.count(parent.get("categoryName")))
    .where(p1)
    .groupBy(node.get("categoryName"))
    .orderBy(nodeLft);
    return em.createQuery(c).getResultList();
    test main():
    Collection<Object> list = ccFacade.findDepthOfSubtreeBy_categoryName("Houseware");
    for (Iterator<Object> iter = list.iterator(); iter.hasNext();) {
    CategorySubcategories cc = (CategorySubcategories) iter.next();
    System.out.println(" name : "+cc.getCategoryName());
    On execution, it thrown exception:
    [Ljava.lang.Object; cannot be cast to au.com.houseware.server.ejb.entity.CategorySubcategories
    Thanks a lot
    Sam                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • I need a help to write the query

    Id
    Child
    Parent
    Is Sub Parent
    Is Parent
    1
    chld1
    y
    2
    chld2
    chld1
    y
    3
    chld3
    chld1
    y
    4
    chld4
    chld1
    5
    chld5
    chld2
    y
    6
    chld6
    chld2
    7
    chld7
    chld5
    8
    chld8
    Q: please check the above table, id no 1-7 are linked with parent and id no 8 is independent child, i need to write a query to display the below result based on the below scenarios
    Scenario 1: if user passes the child 1 the result should be as showed below table all 7 rows need to show.
    Scenario 2: if user passes the child in between child 1 - child 7 then also the result should be as showed below table all 7 rows.
    RESULT
    Id
    Child
    Parent
    1
    chld1
    2
    chld2
    chld1
    3
    chld3
    chld1
    4
    chld4
    chld1
    5
    chld5
    chld2
    6
    chld6
    chld2
    7
    chld7
    chld5
    Thanks in advance

    Hi,
    next time please post sample data as CREATE TABLE and INSERT statements or with clause like this:
    with mychildren as
       select 1 id, 'chld1' chld, null    prnt, null is_sub_parent, 'Y'  is_parent from dual union all 
       select 2 id, 'chld2' chld, 'chld1' prnt, 'Y'  is_sub_parent, null is_parent from dual union all 
       select 3 id, 'chld3' chld, 'chld1' prnt, 'Y'  is_sub_parent, null is_parent from dual union all 
       select 4 id, 'chld4' chld, 'chld1' prnt, null is_sub_parent, null is_parent from dual union all 
       select 5 id, 'chld5' chld, 'chld2' prnt,'Y'   is_sub_parent, null is_parent from dual union all 
       select 6 id, 'chld6' chld, 'chld2' prnt, null is_sub_parent, null is_parent from dual union all 
       select 7 id, 'chld7' chld, 'chld5' prnt, null is_sub_parent, null is_parent from dual union all 
       select 8 id, 'chld8' chld, null    prnt, null is_sub_parent, null is_parent from dual
    Here a couple of test with chld7 and chld1
    with mychildren as
       select 1 id, 'chld1' chld, null    prnt, null is_sub_parent, 'Y'  is_parent from dual union all 
       select 2 id, 'chld2' chld, 'chld1' prnt, 'Y'  is_sub_parent, null is_parent from dual union all 
       select 3 id, 'chld3' chld, 'chld1' prnt, 'Y'  is_sub_parent, null is_parent from dual union all 
       select 4 id, 'chld4' chld, 'chld1' prnt, null is_sub_parent, null is_parent from dual union all 
       select 5 id, 'chld5' chld, 'chld2' prnt,'Y'   is_sub_parent, null is_parent from dual union all 
       select 6 id, 'chld6' chld, 'chld2' prnt, null is_sub_parent, null is_parent from dual union all 
       select 7 id, 'chld7' chld, 'chld5' prnt, null is_sub_parent, null is_parent from dual union all 
       select 8 id, 'chld8' chld, null    prnt, null is_sub_parent, null is_parent from dual
    , find_root as
        select chld
          from mychildren
         where prnt is null
         start with chld='chld1'  --- this is your input
       connect by prior prnt=chld
    select id, chld, prnt
       from mychildren     
      start with chld=(select chld from find_root)
    connect by prior chld=prnt
            ID CHLD  PRNT
             1 chld1     
             2 chld2 chld1
             5 chld5 chld2
             7 chld7 chld5
             6 chld6 chld2
             3 chld3 chld1
             4 chld4 chld1
    Changing it to chld7 does not change the output.
    Output is now sorted according hierarchical query. If you need a different sort order you can specify what you want.
    Regards.
    Al

  • Need a help to write the query

    Hi,
    I need a small help to write the query.
    I have a table contains couponid,coupon,createdate,expirationdate,assigndate from couponday table
    i want to write the query to select the coupon whose Expiry date in the table is NOT within 30 days.
    Thanks in advance

    Hi,
    user586 wrote:
    i want to write the query to select the coupon whose Expiry date in the table is NOT within 30 days.If you mean expirationdate (datatype: DATE) is not within 30 days (past or future) of run time, then:
    SELECT  coupon          -- or whatever columns you want
    FROM    table_x
    WHERE   expirationdate  NOT BETWEEN  SYSDATE - 30
                                AND      SYSDATE + 30
    ;

  • Need to write a query while configuring Database Adapter

    Hi,
    I am working in BPEL.i need to write a query while configuring the DB adapter. i need to query a table which contains five rows each row containing 7 columns. my query should be like if i give the first column name(for eg:Title) it should return the complete row(i.e all the 7 columns in a row).
    So after deploying during testing when i give the Column name(Title) in the BPEL console it should return the row.
    How to write a query such tht if i give any title name in the five rows it should return the respective row
    please help me out.
    Regards,
    Mohamed

    Hi,
    I got the answer for this.its working fine now.
    the query is: select TITLE,..... from movie where (TITLE =#title);
    The second "title" will be the one which i am going to give in bpel console
    so it wil check with the "TITLE" in the table and execute the query.
    Regards,
    Mohamed

Maybe you are looking for

  • Get table name of a record

    Hello every body, I am trying to create a procedure in pl/sql which can takes in input a record and its output is the table name of the record....i don't know how to do this in pl/sql...can u help me? Thanks.

  • Oracle HRMS training form Oracle University

    Oracle HRMS training form Oracle University Approved Education Center iWare Logic iWare Logic provides "Oracle Apps Training" and Certification in Oracle HRMS in association with Oracle University. Oracle HRMS Training and Certification topics E-Busi

  • My macbook pro retina is not working camera after updating Mountain lion.

    My macbook pro retina is not working camera after updating Mountain lion. I have also updated to latest update 10.8.1. Still its the same.

  • Firefox crashes Plug in

    Firefox has been continuously crashing and then stating that firefox plug-in has crashed. And, it still crashes on Firefox Safemode. Please Respond ASAP; It's unfortunately Exam Week.. bp-7f1efe33-6c8f-4aa2-a447-452de2140919 bp-7f1efe33-6c8f-4aa2-a44

  • Can I update iWeb from a different Mac

    My MacBookPro went down last week. I need to update our website, can I do it from the MacBook? If so, how? I use iWeb & I think I publish to Moible Me, but I am really not sure at this point?