Converting query to use joins

My current query works perfectly.
SELECT so.* FROM shipping_order so WHERE (so.submitter = 20) OR (so.requestor_id IN (SELECT poc.objid FROM point_of_contact poc WHERE poc.ain = 20)) OR so.objid IN (SELECT ats.shipping_order_id FROM ac_to_so ats WHERE (ats.access_control_id IN (selectac. objid FROM access_control ac WHERE ac.ain = 20 OR ac.group IN ('buyers', 'managers'))))
But when I try to create it using join statements I do not get the correct results, or any results for that matter.
Here is the query with joins.
SELECT so.* FROM shipping_order so INNER JOIN point_of_contact ON (so.requestor_id = poc.objid AND poc.ain = 20) INNER JOIN ac_to_so ats ON (so.objid = ats.shipping_order_id) INNER JOIN access_control ac ON (ats.access_control_id = ac.objid AND (ac.group IN ('buyers', 'managers') OR ac.ain = 20)) WHERE (so.submitter = 20)
Any ideas on what I am doing wrong. I tried outer joins as well and did not get the results either.
TIA.
Edited by: user9522282 on Mar 11, 2009 6:27 AM fixed typo

Oh sorry. Here is the sql. Thanks!
create table point_of_contact
     objid number not null,
     ain number not null,
     constraint point_of_contact_pk primary key (objid)
create table access_control
     objid number not null,
     ain number,
     user_group varchar2(64 byte),
     constraint access_control_pk primary key (objid)
create table shipping_order
     objid number not null,
     submitter number not null,
     requestor_id number not null,
     constraint shipping_order_pk primary key (objid)
create table ac_to_so
     shipping_order_id number not null,
     access_control_id number not null,
     constraint ac_to_so_pk primary key (shipping_order_id, access_control_id),
     constraint ac_to_so_access_control_fk1 foreign key (access_control_id)
          references access_control (objid),
     constraint ac_to_so_shipping_order_fk1 foreign key (shipping_order_id)
          references shipping_order (objid),
insert into point_of_contact (objid,ain) values (2,37);
insert into point_of_contact (objid,ain) values (1,20);
insert into access_control (objid, ain) values (1, 20);
insert into access_control (objid, user_group) values (2, 'managers');
insert into shipping_order (objid, submitter, requestor_id) values (1,20,1);
insert into shipping_order (objid, submitter, requestor_id) values (2,23,2);
insert into shipping_order (objid, submitter, requestor_id) values (3,23,2);
insert into ac_to_so (shipping_order_id, access_control_id) values (1, 1);
insert into ac_to_so (shipping_order_id, access_control_id) values (2, 2);
select so.* from shipping_order so where (so.submitter = 20)
     or (so.requestor_id in (select poc.objid from point_of_contact poc where poc.ain = 20))
     or so.objid in (select ats.shipping_order_id from ac_to_so ats where
     (ats.access_control_id in (select ac.objid from access_control ac where ac.ain = 20
     or ac.user_group in ('buyers', 'managers'))));

Similar Messages

  • How can i fetch records from 3 tables in a single query  without using join

    Hi.
    Can any body please tell me <b>How can i fetch records from 3 tables with a single query  without using joins</b>
    Thanx
    prabhudutta

    Hi Prabgudutta,
    We can fetch the data by using the views concept.
    Go throuth this info we can know the how to create view and same like database table only we can fetch the data.
    Views conatin the data at runtime only.
    Four different view types are supported. These differ in the
    way in which the view is implemented and in the methods
    permitted for accessing the view data.
    Database views are implemented with an equivalent view on
    the database.
    Projection views are used to hide fields of a table (only
    projection).
    Help views can be used as selection method in search helps.
    Maintenance views permit you to maintain the data
    distributed
    on several tables for one application object at one time.
    step by step creation of Maintenance view:
    With the help of the table maintenance generator, you are able to maintain the ENTRIES of the table in SM30 transaction.
    It can be set in transaction SE11 - Tools - Table maintenance generator.
    Table maintanance Generator is used to manually input values using transaction sm30
    follow below steps
    1) go to se11 check table maintanance check box under attributes tab
    2) utilities-table maintanance Generator-> create function group and assign it under
    function group input box. Also assign authorization group default &NC& .
    3) select standard recording routine radio in table table mainitainence generator to move table
    contents to quality and production by assigning it to request.
    4) select maintaience type as single step.
    5) maintainence screen as system generated numbers this dialog box appears when you click on create button
    6) save and activate table
    One step, two step in Table Maintenance Generator
    Single step: Only overview screen is created i.e. the Table Maintenance Program will have only one screen where you can add, delete or edit records.
    Two step: Two screens namely the overview screen and Single screen are created. The user can see the key fields in the first screen and can further go on to edit further details.
    SM30 is used for table maintenance(addition or deletion of records),
    For all the tables in SE11 for which Table maintenance is selected , they can be maintained in SM30
    Sm30 is used to maintain the table ,i.e to delete ,insert or modify the field values and all..
    It creates the maintenance screen for u for the aprticular table as the maintenance is not allowed for the table..
    In the SE11 delivery and maintenance tab, keep the maintenance allowed..
    Then come to the SM30 and then enter the table name and press maintain..,
    Give the authorization group if necessary and give the function group and then select maintenance type as one step and give the screen numbers as system specified..
    Then create,,,
    Then u will able to see the maintenance view for the table in which u can able to insert and delete the table values...
    We use SM30 transaction for entering values into any DB table.
    First we create a table in SE11 and create the table maintenance generator for that Table using (utilities-> table maintenance generator) and create it.
    Then it will create a View.
    After that from SM30, enter the table name and Maintain, create new entries, change the existing entries for that table.
    Hope this resolves your query.
    Reward all the helpful answers.
    Rgds,
    P.Naganjana Reddy

  • Rewrite the query with out joins and group by

    Hi,
    This was an interview question.
    Table Names: bookshelf_checkout
    bookshelf
    And the join condition between these two tables is title
    We need to rewrite below query without using join condition and group by clause ?
    SELECT b.title,max(bc.returned_date - bc.checkout_date) "Most Days Out"
               FROM bookshelf_checkout bc,bookshelf b
               WHERE bc.title(+)=b.title
               GROUP BY b.title;When I was in college, I read that most of the SELECT statements can be replaced by basic SQL operations (SET OPERATORS). Now I am trying to rewrite the query with SET operators but not able to get the exact result.
    Kindly help me on this.
    Thanks,
    Suri

    Something like this?
      1  WITH books AS (
      2  SELECT 'title 1' title FROM dual UNION ALL
      3  SELECT 'title 2' FROM dual UNION ALL
      4  SELECT 'title 3' FROM dual ),
      5  bookshelf AS (
      6  SELECT 'title 1' title, DATE '2012-05-01' checkout_date, DATE '2012-05-15' returned_date FROM dual UNION ALL
      7  SELECT 'title 1' title, DATE '2012-05-16' checkout_date, DATE '2012-05-20' returned_date FROM dual UNION ALL
      8  SELECT 'title 2' title, DATE '2012-04-01' checkout_date, DATE '2012-05-15' returned_date FROM dual )
      9  SELECT bs.title, MAX(bs.returned_date - bs.checkout_date) OVER (PARTITION BY title) FROM bookshelf bs
    10  UNION
    11  (SELECT b.title, NULL FROM books b
    12  MINUS
    13* SELECT bs.title, NULL FROM bookshelf bs)
    SQL> /
    TITLE   MAX(BS.RETURNED_DATE-BS.CHECKOUT_DATE)OVER(PARTITIONBYTITLE)
    title 1                                                           14
    title 2                                                           44
    title 3Lukasz

  • Using join and batch reading in the same query

    Hi,
    I wonder if it is possible to use "Joining" and "batch reading" in the same query.
    For example I Have
    A -> 1-1 B
    A -> 1-1 B
    B -> 1-M C
    This is the case where I have two separate 1-1 relationships to the same class B from A. Toplink 10.0.3 can manage it nicely through joining.
    Now, I would like to read a set of As (with its 2 Bs) and all Cs for each B.
    It seems that the following configuration does not work:
    A -> 1-1 B (use joining)
    A -> 1-1 B (use joining)
    B -> 1-M C (Batch read)
    Any help would be greatly appreciated
    Tony.

    James,
    Would you be so kind to look at the following code?
    Am I formulating it correctly to achieve my desired behavior?
    Trip.class -> 1-1 PickupStop
    Trip.class -> 1-1 DropoffStop
    PickupStop and DropoffStop extend Stop and use same table (STOP)
    Stop -> 1-M StopEvents
    I would like to fetch all Trips, with their Stops and all StopEvents in 2 queries:
    1. Trip joined with Stop
    2. Batchread StopEvents
    Code:
    ReadAllQuery raq = new ReadAllQuery(Trip.class);
    Expression qexp1 = new ExpressionBuilder();
    Expression qexp2 = new ExpressionBuilder();
    raq.addJoinedAttribute("pickupStop");
    raq.addJoinedAttribute("dropoffStop");
    raq.addBatchReadAttribute(qexp1.get("pickupStop").get("vStopEvents"));
    raq.addBatchReadAttribute(qexp2.get("dropoffStop").get("vStopEvents"));

  • Issues with query using joins in 3 tables

    I am trying to fetch data from 3 tables (Project,RIsk and Issues) using join. There are Risks associated with some projects and Issues associated with some projects.
    ProjectID is primary key in Project table.
    RiskID is primary key in risk table. ProjectID is foreign key.
    IssueID is primary key in Issue table.ProjectID is foreign Key.
    I need the projectname, count of risks for projects, count of issues for projects. I am using joins in all the 3 tables. Issue here is, its giving me double of count of risks and issues for each project.
    Please advise how can I get the correct number. I have used the below query,
    select p.projectname,count(r.riskid),count(i.issueid) from project as p
    left outer join risk as r on p.projectid=r.projecctid
    left outer join issue as i on p.projectid=i.projectid
    group by
    p.projectname
    thanks

    Hi All,
    I got a new requirement to count, the number of high priority risks as well as high priority issues along with the other details. I modified the below table to include the changes, but I am not getting the desired result. Could you please help?
    Original query:
    select p.projectname,count(distinct r.riskid), count(distinct i.issueid) from project as p
    left outer join risk as r on p.projectid=r.projecctid
    left outer join issue as i on p.projectid=i.projectid
    group by p.projectname
    Modified query:
    select p.projectname,count(distinct r.riskid),sum(case when r.riskpriority='high' then 1 else 0 end), sum(case when i.issuepriority='high' then 1 else 0 end),count(distinct i.issueid) from project as p
    left outer join risk as r on p.projectid=r.projecctid
    left outer join issue as i on p.projectid=i.projectid
    group by p.projectnameI should get the desired result as:XYZ,8,1,4,4But I am getting:XYZ,8,4,4,32thanks for the reply.

  • Opitmizing sql query using join

    Hello all,
    I have the following query that needs to be written using Joins. I am not sure if this is the correct place to post this question
    Tables used:
    1. activities: (a_id, n_id, market, amount, act_type, act_number, act_seq) --the money paid by the registrant for the market.
    2. market_reg (a_id, n_id, market, reg_stage) -- for each market there are registrants
    3. market (market) -- stores market details
    I need to get sum of total_payment_amount using the condition. I know the query is not opitmized and its not the correct way to get info. I was
    wondering if you guys can suggest me a query that will pull the information by using joins
    SELECT a.a_id, a.n_id, SUM (a.total_payment_amount)
    FROM activities a
    WHERE a.market = 'marketname'
    AND a.a_id||a.n_id IN
    (SELECT mr.a_id||mr.n_id
    FROM market_reg mr
    WHERE mr.market = 'marketname'
    AND mr.reg_stage = 'P'
    AND mr.n_id <> 0)
    AND (a.act_type = 'A'
    OR (a.act_type IS NULL
    AND a.act_number||act_seq IN
    ( SELECT a1.act_number||a1.act_seq
    FROM activities a1
    WHERE a1.market = 'marketname'
    GROUP BY a1.act_number||a1.act_seq
    HAVING COUNT (a1.act_number||a1.act_seq) = 1)))
    GROUP BY a.a_id, a.n_id;
    Thanks

    Hi,
    I see you have already re-posted this on a more appropriate forum, the SQL and PL/SQL forum.
    Thanks,
    Gary

  • About SQL Query using joins

    Hi,
    I want to write a SQL statement using Joins. The base table "A" has about 100 fields and the join table "B" a few. I would like to fetch all fields from table "A" and a few from table "B".
    Is there a way to write a query wherein I can use "Select * " for table "A" rather than writing all 100 field name in the query? Please keep in mind that I want to use a Join.
    Thanks.

    Hi Thomas,
    but if there are some fields which are in both tables, SELECT * will be not sufficient. E.g. fields ERNAM, ERDAT, AENAM, AEDAT are such fields which can occur in more tables. In case that a target area will contain these fields, by * with addition INTO CORRESPONDING FIELDS OF, you are not able to specify from which table these values should be taken. In such case, it can be solved by specifying field list dynamically. If it is not that case SELECT * is sufficient. You should check intersection of common fields for tables you are joining. Thereafter you should decide if you can use SELECT *.
    Maybe for better understanding, what exactly I am talking about, look at this example:
    TYPES: BEGIN OF ts_data,
            ernam TYPE mara-ernam,
           END OF ts_data.
    DATA: ls_data TYPE ts_data,
          ls_mara TYPE mara,
          ls_mchb TYPE mchb.
    START-OF-SELECTION.
      ls_mara-matnr = '1'.
      ls_mchb-matnr = ls_mara-matnr.
      ls_mara-ernam = 'A'.
      ls_mchb-ernam = 'B'.
      INSERT mara FROM ls_mara.
      INSERT mchb FROM ls_mchb.
      SELECT SINGLE * FROM mara INNER JOIN mchb ON mara~matnr = mchb~matnr INTO CORRESPONDING FIELDS OF ls_data.
      ROLLBACK WORK.
    You as a developer are not able to tell from which table common fields should be selected. But maybe this is really too specific case...
    Regards,
    Adrian

  • Query using JOIN

    Hi,
    my tables structure looks:
    Column names:
    rhead
    bu
    sub_bu
    report_order
    sub_bu_order
    q1py
    My query is:
    select Rhead,bu,Sub_bu,report_order,sub_bu_order,q1py,case
              when sub_bu='ISS' then (select q1py from tsg a where a.sub_bu='ESS' and a.rhead=b.rhead)
              when sub_bu='TS' then (select q1py from tsg a where a.sub_bu='Services' and a.rhead=b.rhead)
              when sub_bu='SW' then (select q1py from tsg a where a.sub_bu='SW' and a.rhead=b.rhead)
              else NULL end as q1py_bu,
              case
              when sub_bu='ISS' then (select q1py from tsg a where a.sub_bu='TSG' and a.rhead=b.rhead)
              when sub_bu like 'R&D' and rhead in ('Region owned opex','% of revenue','Region opex','Region opex%') then
              (select q1py from tsg a where a.sub_bu like 'TSG' and a.rhead=b.rhead)
              else NULL end as q1py_tot from tsg b where report_order=1
    Result:
    rhead bu sub_bu report_order sub_bu_order q1py q1py_bu q1py_tot
    orders ESS ISS 1 1 1162 1778.4 2953.9
    here i am using the sub query to produce the result. I need to give the same result by using JOINS.
    So any one help me, by using JOINS instead of SUB QUERY and produce the same result
    Thanx in advance

    Hi,
    this is my query
    select
    Rhead,BU,Sub_bu,report_order,sub_bu_order,q1py,
    case
              when sub_bu='ISS' then (select q1py from tsg a where a.sub_bu='ESS' and a.rhead=b.rhead)
              when sub_bu='TS' then (select q1py from tsg a where a.sub_bu='Services' and a.rhead=b.rhead)
              when sub_bu='SW' then (select q1py from tsg a where a.sub_bu='SW' and a.rhead=b.rhead)
              else NULL end as q1py_bu,
    case
              when sub_bu='ISS' then (select q1py from tsg a where a.sub_bu='TSG' and a.rhead=b.rhead)
              when sub_bu like 'R&D' and rhead in ('Region owned opex','% of revenue','Region opex','Region opex%') then
              (select q1py from tsg a where a.sub_bu like 'TSG' and a.rhead=b.rhead)
              else NULL end as q1py_tot
    last_update from tsg where @condition;
    i will use the different conditions. they are
    1.sub_bu<>bu and report_order<=8
    2.report_order > 8 and report_order<11 and sub_bu not in (‘TSG’)
    3.report_order > 10 and report_order <14
    4.report_order > 13
    i used the above query and getting some time.
    so i am using the below query as suggested by forum earlier.
    select
    Rhead,BU,Sub_bu,report_order,sub_bu_order,q1py,
    case
    when sub_bu='ISS'
    then max(case when sub_bu='ESS' then q1py end) over(partition by rhead)
    when sub_bu='TS'
    then max(case when sub_bu='Services' then q1py end) over(partition by rhead)
    when sub_bu='SW'
    then max(case when sub_bu='SW' then q1py end) over(partition by rhead)
    end as q1py_bu,
    case
    when sub_bu='ISS'
    then max (case when sub_bu='TSG' then q1py end) over (partition by rhead)
    when sub_bu = 'R&D' and rhead in ('Region owned opex','% of revenue','Region opex','Region opex%')
    then max(case when sub_bu = 'TSG' then q1py end) over (partition by rhead)
    end as q1py_tot, last_update from tsg where @condition;
    I am getting better result by this query.
    but the problem is this query gives wrong output for first two conditions(1.sub_bu<>bu and report_order<=8
    2.report_order > 8 and report_order<11 and sub_bu not in (‘TSG’). The value is not displayed for the virtual column q1py_bu and q1py_tot.
    i am getting this warning message too
    Warning: Null value is eliminated by an aggregate or other SET operation.
    I am not able to find the solution. so plz do help in this..
    other than this every thing is fine
    thanks

  • Write the following query using JOIN keyword ?

    Qest:
    Write the following query using JOIN keyword ?
    select ID_category from category_master X
    where Exist(select 1 from sub_category Y where
    X.ID_category=Y.ID_category)Edited by: 799660 on Oct 3, 2010 6:05 AM

    select  X.ID_category
      from  category_master X join (select distinct ID_category from sub_category) Y
             on (X.ID_category=Y.ID_category)
    /SY.

  • Select Query using Joins

    Hi,
    Please give me the Select query
    I have to fetch   EBELN,BUKRS,LIFNR,BSART,EKORG,EKGRP,WAERS,WKURS  from EKKO and
                          EBELP,LGORT,MATKL ,WERKS,BEDNR,IDNLF,BPRME,NETPR   from EKPO and
                         MENGE, SAKTO,AUFNR,ANLN1,GSBER,PS_PSP_PNR                from EKKN and
                         LPEIN,EINDT,SLFDT,                                                                    from EKET.
    I have to fetch all the data into an single internal table(Mandatory) by a select query using Joins.
    EKKO is having EBELN as primary key
    EKPO is having EBELN,EBELP as primary key
    EKKN is having EBELN,EBELP as primary key
    EKET is having EBELN,EBELP as primary key
    Can anybody Please give me the Select query.
    With Regards
    Ajay

    Hi ,
    I am sending this sample coed for the Inner joins .Hope this will help you:
    Inner joins using 3 tables 
    Try this :-
    SELECT stpostlnr stpoidnrk mastmatnr maramtart stpo~menge 
    INTO CORRESPONDING FIELDS OF TABLE zmat1 FROM mast 
    JOIN stpo ON stpostlnr = maststlnr 
    JOIN mara ON maramatnr = mastmatnr 
    WHERE stpostlty = 'M' "AND stpoidnrk IN s_matnr 
    AND mast~werks = 1000. 
    Here s_matnr is a select-options on the selection-screen. 
    Or this. 
    Code: 
         Select single VbrkBukrs VbrkKunrg    Vbrk~Vbeln 
                       VbrkFkdat VbrkBstnk_Vf Vbrk~Zterm 
                       Tvzbt~Vtext 
                       VbakVbeln VbakBstdk 
                       LikpVbeln Likplfdat    Likp~Lfuhr 
           into w_vbrk 
           from vbrk 
          inner join       Tvzbt on TvzbtZterm        = VbrkZterm      and 
                                    Tvzbt~Spras        = sy-langu 
          Inner join       Vbfa  as SalesLnk 
                                 on SalesLnk~vbeln     = pu_vbeln        and 
                                    SalesLnk~vbtyp_v   = c_order 
                inner join Vbak  on VbakVbeln           = SalesLnkVbelv
          Inner join       Vbfa  as DeliveryLnk 
                                 on DeliveryLnk~vbeln   = pu_vbeln       and 
                                    DeliveryLnk~vbtyp_v = c_Delivery 
                inner join Likp  on LikpVbeln          = DeliveryLnkVbelv 
          where vbrk~vbeln = pu_Vbeln. 
    This code locates sales, delivery and payment terms info from a billing document number. 
    or
    Here, this one also works fine :
    select zfpcdcadivi zfpcdproforma zfpcdfactura zfpcdaniofactura 
    zfpcdmontousd zfpcdmontoap zfpcdebeln zfpcdinco1 
    zfpcdlifnr lfa1name1 zcdvsstatus zfpcdconint 
    into it_lista 
    from zfpcd inner join zcdvs 
    on zfpcdebeln = zcdvsebeln 
    and zfpcdproforma = zcdvsproforma 
    and zfpcdlifnr = zcdvslifnr 
    inner join lfa1 
    on zfpcdlifnr = lfa1lifnr 
    where zcdvs~status = '04'. 
    Also Here is another solution that just uses inner joins:
    SELECT vbakvbeln vbfaerdat INTO (itab-vbeln, itab-wadat)
    FROM ( vbak INNER JOIN vbap
    ON vbapvbeln = vbakvbeln )
    INNER JOIN vbfa ON vbakvbeln = vbfavbelv
    WHERE vbak~kunnr = m_wm AND
    vbak~vbtyp = 'C' AND
    vbfa~erdat IN s_date AND
    vbap~matnr = 'MZ1807F' AND
    vbfaposnv = vbapposnr AND
    vbfa~vbtyp_n = 'J'.
    <REMOVED BY MODERATOR>
    Cheers,
    Chandra Sekhar.
    Edited by: Alvaro Tejada Galindo on Apr 10, 2008 5:20 PM

  • Can i join a list in sub-site using Join query?

    Hi all,
    I'm newbie and i have tried to join a list in parent site with a list in sub-site using Join query but i always get the error. How can i do this action? Thanks!

    You could try using SPSiteDataQuery or a DataTable.
    http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spsitedataquery%28v=office.14%29.aspx
    http://sharepoint.stackexchange.com/questions/75713/is-it-possible-to-populate-result-by-joining-two-lists-throughout-the-site-colle
    --Cheers

  • Get query using joins

    My Table
    employee table
    =emp id .. emp name
    1    Ravi
    2    Kumar
    3    Gopal
    4    Selvam
    5    Raj
    6    Sekar
    dept table
    dept id .. emp id .. salary
    1                  1    10000
    1                  2    20000
    2                   3    30000
    2                     4    40000
    Query
    1. Using Join, select Employees not in the dept table
    2. select max  of salary , dept id , emp_Name from dept  group by dept
    Kindly provide me the query.
    ShanmugaRaj

    Looks like homework/exercise given to you. Did you try to write queries by yourself? :)
    You may ask your doubts/confusion.
    -- 1)
    SELECT e.empid
    ,e.empname
    FROM employee e
    LEFT JOIN dept d ON e.empid = d.empid
    WHERE d.empid IS NULL
    --2)
    SELECT MAX(d.salary)
    ,d.deptid
    ,e.empName
    FROM dept d
    FULL JOIN employee e ON d.empid = e.empid
    GROUP BY d.deptid, e.empname
    -Vaibhav Chaudhari

  • SQL Query Using Join

    Hi,
    I am trying to join two tables using joining.
    SQL> select * from test10;
    ID
    1
    2
    SQL> select * from test11;
    ID
    1
    3
    4
    My expected output is
    ID
    1
    2
    3
    4
    I am able to do this using "Union"
    SQL> select * from test10
    2 union
    3 select * from test11;
    ID
    1
    2
    3
    4
    But i want to achieve this using join. Please help..
    Thanks & Regards,
    Arijit

    Hi, Arijit,
    The way to do that with a join is FULL OUTER JOIN, like this:
    SELECT       NVL (t10.id, t11.id)     AS id
    FROM               test10  t10
    FULL OUTER JOIN  test11  t11  ON   t10.id  = t11.id
    ORDER BY  1
    ;If that's exactly what you're trying to do, you should stick with the UNION.
    FULL OUTER JOIN is good when there are other columns involved.

  • Issue with select query to fetch data using Join from two tabels

    Hello All-
    I want to fetch the ShowName as "SUN NIGHTLY NEWS" and EpisodeName as "091706"
    based on the condition a.TitleNo=b.TitleNo and a.seriesNo=b.TitleNo.
    If i use the only first condition-a.TitleNo=b.TitleNo than output is displayed as-
    SchedItemNo |      Showname|      EpisodeName
    2702154     |     091706     |     091706
    If i use the second Condition-a.seriesNo=b.TitleNo than Output is displayed as-
    SchedItemNo|     Showname      |     EpisodeName
    2702154     |     SUN NIGHTLY NEWS |     SUN NIGHTLY NEWS
    Than i tried following Query to use the Union based on two conditions:-
    Select distinct a.SchedItemNo,b.TitleName,b.TitleName as EpisodeName
    from ScheduleItem a,Titles b where a.TitleNo=b.TitleNo and
    a.ScheditemNo in ('2702154')
    Union All
    Select distinct a.SchedItemNo,b.TitleName,b.TitleName as EpisodeName
    from ScheduleItem a,Titles b where b.TitleNo=a.SeriesNo and
    a.ScheditemNo in ('2702154')
    than it display the following result-
    SchedItemNo|     Showname |     EpisodeName
    2702154     |     091706          |     091706
    2702154     |     SUN NIGHTLY NEWS |     SUN NIGHTLY NEWS
    Here also values are not what i want :(
    I want the result to be displayed as using SQL:-
    SchedItemNo |     Showname      |     EpisodeName
    2702154     |     SUN NIGHTLY NEWS |     091706
    Please help me out!
    Thanks in Advance for putting your efforts.Looking forward for your replies.

    SQL> create table scheduleitem
      2  as
      3  select 2702154 scheditemno, 1 titleno, 11 seriesno from dual
      4  /
    Tabel is aangemaakt.
    SQL> create table titles
      2  as
      3  select 1 titleno, '071706' titlename from dual union all
      4  select 11, 'SUN NIGHTLY NEWS' from dual
      5  /
    Tabel is aangemaakt.
    SQL> Select distinct a.SchedItemNo,b.TitleName,b.TitleName as EpisodeName
      2  from ScheduleItem a,Titles b where a.TitleNo=b.TitleNo and
      3  a.ScheditemNo in ('2702154')
      4  /
                               SCHEDITEMNO TITLENAME        EPISODENAME
                                   2702154 071706           071706
    1 rij is geselecteerd.
    SQL> Select distinct a.SchedItemNo,b.TitleName,b.TitleName as EpisodeName
      2  from ScheduleItem a,Titles b where b.TitleNo=a.SeriesNo and
      3  a.ScheditemNo in ('2702154')
      4  /
                               SCHEDITEMNO TITLENAME        EPISODENAME
                                   2702154 SUN NIGHTLY NEWS SUN NIGHTLY NEWS
    1 rij is geselecteerd.
    SQL> Select distinct a.SchedItemNo,b.TitleName,b.TitleName as EpisodeName
      2  from ScheduleItem a,Titles b where a.TitleNo=b.TitleNo and
      3  a.ScheditemNo in ('2702154')
      4  Union All
      5  Select distinct a.SchedItemNo,b.TitleName,b.TitleName as EpisodeName
      6  from ScheduleItem a,Titles b where b.TitleNo=a.SeriesNo and
      7  a.ScheditemNo in ('2702154')
      8  /
                               SCHEDITEMNO TITLENAME        EPISODENAME
                                   2702154 071706           071706
                                   2702154 SUN NIGHTLY NEWS SUN NIGHTLY NEWS
    2 rijen zijn geselecteerd.
    SQL> select a.SchedItemNo "SchedItemNo"
      2       , show.TitleName "Showname"
      3       , episode.TitleName "EpisodeName"
      4    from ScheduleItem a
      5       , Titles episode
      6       , Titles show
      7   where a.TitleNo = episode.TitleNo
      8     and a.SeriesNo = show.TitleNo
      9  /
                               SchedItemNo Showname         EpisodeName
                                   2702154 SUN NIGHTLY NEWS 071706
    1 rij is geselecteerd.Regards,
    Rob.

  • Query to count no.of orders using joins and subqueries

    I have 3 tables i want to show the no. of orders when order placed date is equal to Create date(user registered date)
    order table contains following columns
    [OrderId]
          ,[UserId]
          ,[OrderPlaced]
          ,[Paid]
          ,[DatePaid]
          ,[PaymentMethod]
          ,[PaymentRef]
          ,[BillTo]
          ,[AddressLine1]
          ,[AddressLine2]
          ,[City]
          ,[County]
          ,[CountryId]
          ,[PostCode]
          ,[Shipped]
          ,[DateShipped]
          ,[Packing]
          ,[ShipTo]
          ,[ShippingAddressLine1]
          ,[ShippingAddressLine2]
          ,[ShippingCity]
          ,[ShippingCounty]
          ,[ShippingCountryId]
          ,[ShippingPostCode]
          ,[ShippingCost]
          ,[ShippingOptionId]
          ,[AllocatedPoint]
          ,[PointValue]
          ,[PromoCode]
          ,[DiscountValue]
          ,[InvoiceNumber]
          ,[IPAddress]
          ,[StatusCode]
          ,[IssueCode]
          ,[USStateId]
          ,[ShippingUSStateId]
          ,[CurrencyCode]
          ,[ExchangeRate]
          ,[LastActivityDate]
          ,[AwardedPoint]
          ,[Archived]
          ,[LastAlertDate]
    aspnet_Membership table contains
    [Password]
          ,[PasswordFormat]
          ,[PasswordSalt]
          ,[MobilePIN]
          ,[Email]
          ,[LoweredEmail]
          ,[PasswordQuestion]
          ,[PasswordAnswer]
          ,[IsApproved]
          ,[IsLockedOut]
          ,[CreateDate]
          ,[LastLoginDate]
          ,[LastPasswordChangedDate]
          ,[LastLockoutDate]
          ,[FailedPasswordAttemptCount]
          ,[FailedPasswordAttemptWindowStart]
          ,[FailedPasswordAnswerAttemptCount]
          ,[FailedPasswordAnswerAttemptWindowStart]
          ,[Comment]
    Account table contains 
    [UserId]
          ,[FirstName]
          ,[LastName]
          ,[Email]
          ,[ContactNumber]
          ,[DOB]
          ,[Note]
    my code is
    SELECT a.UserId, m.Email, o.OrderPlaced, o.OrderId, m.CreateDate
    FROM Account a, aspnet_Membership m, Orders o
    where a.UserId=o.UserId and a.Email=m.Email ORDER BY a.UserId 
    I had displayed the required details using joins but now i want the number of orders when order placed date is equal to Create date(user registered date)
    can anyone help me iam a fresher
    Thanks in advance.

    You cant use subquery in ORDER BY like this.
    you need to do it like this
    SELECT a.UserId, m.Email, o.OrderPlaced, o.OrderId, m.CreateDate
    FROM Account a
    INNER JOIN aspnet_Membership m
    ON a.Email=m.Email
    INNER JOIN (SELECT *,COUNT(OrderId) OVER (PARTITION BY Createddate) AS Cnt FROM Orders) o
    on a.UserId=o.UserId
    ORDER BY a.UserId,o.Cnt
    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

Maybe you are looking for

  • Purchase Order Quantity

    Hi ABAP Gurus, Requirment: I need to adjust only the delivery quantity of the PO or STO. Options to update: BAPI Func.Mod, BDC, or any Func. mod particularly for this req.  Plz suggest which I need to use for update the Orders to improve the performa

  • Vendor Outstanding

    Hi We need to see the vendor out standing. Is thr any t code or report will give vendor outstanding balace.? Vijay

  • Creating InfoSources in BI 7.0

    Greetings from Manila! I'm new to the BI world and as such, am learning from doing.  I got training from SAP Solutions Academy last year for BW 3.5 but have only begun using BI now.  Challenge is I'm using BI 7, which is slightly different from using

  • BSP on cellular phones

    Hello all ! I have a tricky question and I have been searching an answer for weeks, unsuccesfully... I would like to develop a little and simple BSP for cellular phones. All seem to be compatible. I can display pages as normally as I hoped... ...but.

  • Flash CS3 Won't Install

    Okay... I seriously am in need of help here. I have downloaded the trial version of Adobe Flash CS3, and for some reason when I run the installer it didn't install it right. At first when I installed this, the program seemed to be in place, but when