SQL - Joins

Hi all.
I am learning join- tables in SQL.
My question relates to the use of WHERE. It is probably best if I show 2 examples:
1 SELECT ename, dname from emp e join dept d on (e.deptno = d.deptno) WHERE ename = 'Jones';
2 SELECT ename, dname from emp e, dept d where e.deptno = d.deptno
So the question is: How do I stipulate in Example 2 that I want the details returned for 'jones' ?
I have tried using AND WHERE, but it doesn't seem to work.
Any thoughts??

Just answered my own Q.!!
2 SELECT ename, dname from emp e, dept d where e.deptno = d.deptno AND ename = 'jones'
Sometimes the simplest solution works.
I have clicked answered. I presume that you cannot obtain points for answering your own question!?

Similar Messages

  • EXEC SQL join in ABAP program

    Hi All,
    I am using EXEC SQL join in my ABAP report,but it is giving dump.could you please correct my following code?
    START-OF-SELECTION.
      CONCATENATE '%' pa_match '%' INTO tp_match.
      EXEC SQL.
        OPEN dbcur FOR
        SELECT  kunnr,name1, banks
               FROM  kna1 as a inner join
               knbk as b
               on akunnr = bkunnr
               WHERE a.kunnr = b.kunnr and
               upper(a~name1) LIKE :tp_match
      ENDEXEC.
      DO.
        EXEC SQL.
          FETCH NEXT dbcur INTO :wa_name1
        ENDEXEC.
        IF sy-subrc <> 0.
          EXIT.
        ENDIF.
        APPEND wa_name1 TO ta_name1.
        COLLECT wa_name1 INTO ta_name1.
      ENDDO.
      EXEC SQL.
        CLOSE dbcur
      ENDEXEC.

    Remove the 'As' from the statement
    EXEC SQL.
      OPEN dbcur FOR
      SELECT kunnr,name1, banks
      FROM kna1 a inner join        "Delete 'AS' here
      knbk b
      on a~kunnr = b~kunnr
      WHERE a.kunnr = b.kunnr and
      upper(a~name1) LIKE :tp_match
    ENDEXEC.

  • SQL JOIN with BPM sql component

    Hello friends.
    How to use SQL JOIN with BPM sql component?
    The tables objects are created but the joined tables belong to different sql components .
    I tried something like that, but a error "table doesn't exist" occours.
    Ex:
    for each element in
    SELECT imuImovelCd
    FROM IMOVEIS_URBANOS,
    Integracao.FGLP.IMOVEIS_PRE_EDITAIS
    WHERE IMOVEIS_URBANOS.imuImovelCd = Integracao.FGLP.IMOVEIS_PRE_EDITAIS.ipeImuCd
    AND Integracao.FGLP.IMOVEIS_PRE_EDITAIS.ipePedNr = 1
    AND Integracao.FGLP.IMOVEIS_PRE_EDITAIS.ipePedAa = 2008
    do
    extend this.imoveis using cdImovel = element.imuimovelcd,
                                  nrImovel = call(DEC_ENDERECO, codimovel : element.imuimovelcd, tipoimovel : 1)
    end
    Edited by: user9008295 on 26/01/2010 05:19

    ok, ok you are right.
    When I try use SQL Statement to make a JOIN with 2 tables on different sql objects, BPM returns "table dosn't exists".
    So.... I change my code. I dont know if this is the best way to do, but... i hope u, or everyone, can help me to do a best work.
    This code works fine.
    for each element in
    SELECT ipeImuCd
         FROM Integracao.FGLP.IMOVEIS_PRE_EDITAIS
         WHERE Integracao.FGLP.IMOVEIS_PRE_EDITAIS.ipePedNr = 1
         AND Integracao.FGLP.IMOVEIS_PRE_EDITAIS.ipePedAa = 2008
    do
         for each element2 in
              SELECT imuImovelDv
              FROM IMOVEIS_URBANOS
              WHERE imuImovelCd = element.ipeImuCd
         do
              extend this.imoveis using cdDvImovel = String(element2.imuImovelDv),
                                            cdImovel = Decimal(element.ipeImuCd),
                                            endereco = call(DEC_ENDERECO, codimovel : element.ipeImuCd, tipoimovel : 1)
         end
    end
    Thx a lot!!!

  • ANSI SQL JOIN

    Hi
    How to use ANSI SQL JOINS (9i) for below query
    SELECT EMP.EMPNO,EMP_T.TNO,EMP_T.SAL1 FROM EMP,EMP_T WHERE EMP.EMPNO=EMP_T.TNO
    UNION ALL
    SELECT EMP.EMPNO,EMP_T.TNO,EMP_T.SAL2 FROM EMP,EMP_T WHERE EMP.EMPNO=EMP_T.TNO
    UNION ALL
    SELECT EMP.EMPNO,EMP_T.TNO,EMP_T.SAL3 FROM EMP,EMP_T WHERE EMP.EMPNO=EMP_T.TNO
    EMPNO TNO SAL1
    7369 7369 100
    7499 7499 1000
    7566 7566 400
    7782 7782 4000
    7369 7369 200
    7499 7499 2000
    7566 7566 500
    7782 7782 5000
    7369 7369 300
    7499 7499 3000
    7566 7566 600
    EMPNO TNO SAL1
    7782 7782 6000
    Regards
    MM

    SELECT EMP.EMPNO,
           EMP_T.TNO,
           EMP_T.SAL1
    FROM   EMP
    JOIN   EMP_T ON ( EMP.EMPNO = EMP_T.TNO )
      UNION ALL
    SELECT EMP.EMPNO,
           EMP_T.TNO,
           EMP_T.SAL2
    FROM   EMP
    JOIN   EMP_T ON ( EMP.EMPNO = EMP_T.TNO )
      UNION ALL
    SELECT EMP.EMPNO,
           EMP_T.TNO,
           EMP_T.SAL3
    FROM   EMP
    JOIN   EMP_T ON ( EMP.EMPNO = EMP_T.TNO )

  • OWB 10.2.0.4 ANSI SQL join problem

    Hi
    Its seams to me, that in OWB 10.2.0.4 there is something broken with ANSI SQL joins and instead of ANSI joins there is used oracle SQL joins only. Maybe someone can point some solutions? I can’t rewrite all mappings with union and other operators. And manually pl/sql editing also would be big problem.

    "Am I correct in assuming you did not code ANSI joins?" -> yes, i am coding Oracle SQL joins and with this option just generating ANSI joins.
    With ANSI SQL join you can use OR and IN operands (and code looks more readable).
    It is question of performance (so for example 80% of dataset you can join by one column other 15% by second etc ..). So this all can be rewritten also in Split->join->union all, but if you have several such joins, this will be painfully.

  • SQL Join Help

    SQL Experts,
    I have a query below. Can I improve the SQL joining order in highlighted section - Lines 31 to 40
    SNIOTM.SNI_PA_OTM_ARC_DRVR -- around 200K rows
    SNIOTM.SNI_PA_ORD_SHP_STATUS -- 8 rows
    Edited by: 922411 on May 12, 2013 7:42 PM

    922411 wrote:
    SQL Experts,
    I have a query below. Can I improve the SQL joining order in highlighted section - Lines 31 to 40
    SNIOTM.SNI_PA_OTM_ARC_DRVR -- around 200K rows
    SNIOTM.SNI_PA_ORD_SHP_STATUS -- 8 rowsYou need not worry about the Joining Order, Oracle CBO is efficient enough to choose the Most Efficient way of joining the tables. However, it will depend on your Oracle Version, which you have not mentioned. If you are 10g or higher then you certainly need not worry.
    If you sense a problem in performance of query, then I will suggest you read the linked threads in {message:id=9360003} and post the details as specified.
    Only this will help us provide releavant suggestions and avoid guessing games.
    PS:- Do not forget to post Oracle Version and the Explain Plan in {noformat}{noformat} tags, exactly as specified.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Help - Bean Binding an SQL join to a gui component(jtable) in Netbeans?

    Good afternoon. I'd like to ask if there is a way to data bind an SQL Join from 2 or more tables to a
    GUI component(Jtable) in Netbeans. All the tutorials show is how to bind all the fields of 1 database table
    to the component. Under the BIND/ELements option the IMPORT DATA TO FORM menu only allows
    you to choose 1 among the database tables from a selected database.
    Is there a way to configure an SQL query and attach it to the component?
    Thanks.

    This is not a Swing problem. Try a NetBeans forum.

  • Converting oracle join to Ansi sql join

    Hi Guys,
    I am new to SQL and trying to convert the following Oracle query (joins) into ANSI sql joins...Can someone please help me?
    SELECT M.EXTERNALCODE, M.NAME AS MNAME, SC.BIRIM, SM.TRANSACTIONDATE, SMD.AMOUNT,
    SMD.UNITPRICE, SM.ID AS SMID, SMD.ID AS SMDID, F.NAME AS FNAME,
    IFNULL (SMD.AMOUNT, 0, SMD.AMOUNT) * IFNULL (SMD.UNITPRICE, 0, SMD.UNITPRICE) AS TOTALPRICE, SMD.AMOUNT AS RECEIVED_QUANTITY,
    PD.ORDERID, PD.AMOUNT QUANTITY, PO.PROCESSDATE
    FROM STOCKMAINTRANSACTION SM,
    STOCKMAINTRANSACTIONDETAIL SMD,
    MATERIAL M,
    STOCKCARD SC,
    FVSTOCK FVS,
    FIRM F,
    PURCHASEORDER PO,
    PURCHASEORDERDETAIL PD,
    PURCHASEORDERDETAILSUPPLIED PDS
    WHERE SM.ID = SMD.MAINTRANSACTIONID
    AND SMD.MATERIALID = M.ID
    AND SMD.STOCKCARDID = SC.ID
    AND SM.PROPREF = FVS.RECORDID(+)
    AND FVS.FIELDID(+) = 2559
    AND FVS.FLEVEL(+) = 'F'
    AND F.ID(+) = SUBSTR (FVS.FVALUE, 1, 9)
    AND SM.TRANSDEFID in (999,2329,2344,2370,150000903,150005362)
    AND SMD.CANCELLED = 0
    AND SMD.STOCKUPDATED = 1
    AND SMD.ID = PDS.STOCKMAINTRANSACTIONDETAILID
    AND PDS.ORDERDETAILID = PD.ORDERDETAILID
    AND PO.ORDERID = PD.ORDERID
    AND (M.ID = {@MATERIALID@} OR {@MATERIALID@} = 0)
    AND (SM.STOREID = {@STOREID@} OR {@STOREID@} = 0)
    AND (F.ID = {@SUPPLIERID@} OR {@SUPPLIERID@} = 0)
    AND SM.TRANSACTIONDATE BETWEEN {@STARTDATE@} AND {@ENDDATE@}
    ORDER BY F.NAME, M.EXTERNALCODE, SM.TRANSACTIONDATE
    Really appreciate the help!
    Thanks.

    Hi,
    Welcome to the forum!
    To convert to ANSI syntax, replace join conditions in the WHERE clause
    FROM           x
    ,             y
    WHERE         x.x1  = y.y1
    AND           x.x2  = y.y2with ON conditions in the FROM clause:
    FROM           x
    JOIN             y   ON    x.x1  = y.y1
                             AND   x.x2  = y.y2In inner joins, conditions that do not reference 2 tables are not really join conditions, so it doesn't matter if they are in the FROM clause or in the WHERE clause.
    In your case
    SM.TRANSDEFID in (999,2329,2344,2370,150000903,150005362)could be part of a join condition involving sm, or it could be in the WHERE clause. Most people find it clearer if 1-table conditions like this are in the WHERE clause.
    Again, this only applies to inner joins. For outer joins, all conditions that apply to a table that may lack matching rows must be included in the FROM clause, like this:
    LEFT OUTER JOIN  fvstock   fvs  ON   sm.propref       = fvs.recordid
                                    AND  fvs.fieldid  = 2559
                        AND  fvs.flevel   = 'F'Try it.
    If you have trouble, post your best attempt, along with CREATE TABLE and INSERT statements for a little sample data from all the tables involved, and the results you want from that data. Simplify the problem. Post only the tables and columns that you don't know how to handle.
    See the forum FAQ {message:id=9360002}
    user8428528 wrote:
    AND (M.ID = {@MATERIALID@} OR {@MATERIALID@} = 0)
    AND (SM.STOREID = {@STOREID@} OR {@STOREID@} = 0)
    AND (F.ID = {@SUPPLIERID@} OR {@SUPPLIERID@} = 0)
    AND SM.TRANSACTIONDATE BETWEEN {@STARTDATE@} AND {@ENDDATE@}This is not valid Oracle SQL. Is {@MATERIALID@} some kind of variable?

  • Pl sql join and selecting columns from join."t"."c": invalid at debug time

    I noticed the error at cc.Country that is shown because cc is not yet there at compile time (got that
    from searching this forum).
    Isnt that a bit weak of oracle sql developer that it doesnt compile from the outside to the inside /core but
    rather form top to bottom?
    Am I right with my conclusion? If so, how to do it otherwise i.e. specifying that cc.country is
    a column from countrycodes joined with table6 ?
    SELECT DISTINCT 0,
    2,
    SUBSTR('metable', 0, 1) || '_ABC',
    'ABC_' || 'metable',
    'ABC ' ||cc.Country ,
    '+'
    FROM table6
    LEFT JOIN COUNTRYCODE cc
    ON cc.Code = metable
    WHERE metable IS NOT NULL
    AND metable <> ''

    metalray wrote:
    hi Boneist
    thanks for your reply
    its in a plsql procedure (10g). well as you see cc is the alias
    of the table COUNTRYCODE. which does exists. the error is at 'ABC ' ||cc.Country'
    telling me"PL/SQL: ORA-01747: invalid user.table.column,..."
    when I put COUNTRYCODE next to table6 in the FROM it works but thats not what I want
    since I want to join both tables not just select from both.Can you give us your exact code and exact error message.
    I'm not finding any problem with using alias names in the query..
    SQL> select d.dname
      2        ,'EMPNAME : '||e.ename
      3  from dept d LEFT JOIN emp e ON e.deptno = d.deptno;
    DNAME          'EMPNAME:'||E.ENAME
    RESEARCH       EMPNAME : SMITH
    SALES          EMPNAME : ALLEN
    SALES          EMPNAME : WARD
    RESEARCH       EMPNAME : JONES
    SALES          EMPNAME : MARTIN
    SALES          EMPNAME : BLAKE
    ACCOUNTING     EMPNAME : CLARK
    RESEARCH       EMPNAME : SCOTT
    ACCOUNTING     EMPNAME : KING
    SALES          EMPNAME : TURNER
    RESEARCH       EMPNAME : ADAMS
    SALES          EMPNAME : JAMES
    RESEARCH       EMPNAME : FORD
    ACCOUNTING     EMPNAME : MILLER
    OPERATIONS     EMPNAME :
    15 rows selected.
    SQL>

  • Malformed SQL Join Created in BO XI SP5

    Hi I am receiving the following message when running a specific universe-based Crystal Report:
    Error in File C:\Program Files\Business Objects\BusinessObjects Enterprise 11.5\Data\procSched\hq-erpboprod.reportjobserver\~tmp1e061e138ef0560.rpt: Failed to retrieve data from the database.
    I can see why it is failing to retrieve data from the database - the SQL that the Crystal is generating is not putting the 'AND' in between each clause in the join statement (see below). However, when I build the same query in Designer, I get the correct SQL results.
    SELECT GLPD.GLDGL, GLPGL.GLGLNM, cvtdate(GLPD.GLDEDT), GLPD.GLDJC, GLPD.GLDEDS, sum(GLPD.GLDBA), GLPD.GLDJB, GLPD.GLDCC, GLPD.GLDCN, GLPPJ.GLPJ, DT_ROLLUPLEV.XAFVVC, trim(GLPPJ.GLPJNM), GLPD.GLDBT, GLPD.GLDBE, GLPD.GLDBL FROM GLPD INNER JOIN GLPMF ON (GLPMF.GLMGL= GLPD.GLDGL AND GLPMF.GLMCO=GLPD.GLDCOGLPMF.GLMIC= GLPD.GLDICGLPMF.GLMPJ= GLPD.GLDPJGLPMF.GLMJB= GLPD.GLDJBGLPMF.GLMCC= GLPD.GLDCCGLPMF.GLMCN= GLPD.GLDCNGLPMF.GLMBK=GLPD.GLDBKGLPD.GLDFY=GLPMF.GLMFYGLPD.GLDFFC=GLPMF.GLMFFCGLPMF.GLMFFY=GLPD.GLDFFYGLPD.GLDFC=GLPMF.GLMFC) RIGHT OUTER JOIN GLPGL ON (GLPMF.GLMGL=GLPGL.GLGL) INNER JOIN GLPPJ ON (GLPMF.GLMPJ=GLPPJ.GLPJ) RIGHT OUTER JOIN ( select distinct xafvk1, xafvvc, xafvvd
    from xapfv
    where xafvfl = 'XAPROJECT'
    and xafvff = 'ROLLUPLEV' ) AS DT_ROLLUPLEV ON (GLPPJ.GLPJNV=DT_ROLLUPLEV.XAFVK1) WHERE ( GLPD.GLDBK='ACT' ) AND ( ( ( GLPPJ.GLPJ ) IN {?Query1_Prompt0} ) AND ( ( GLPMF.GLMBK )=('{?Query1_Prompt1}') ) AND GLPGL.GLGL IN {?Query1_Prompt2} AND DT_ROLLUPLEV.XAFVVC IN {?Query1_Prompt3} AND ( GLPD.GLDEDT <= RCVTDATE(( XCVTDATE(DATE(SUBSTRING({?Query1_Prompt4},1,10))) )) AND GLPD.GLDEDT >= RCVTDATE(( XCVTDATE(DATE(SUBSTRING({?Query1_Prompt5},1,10))) )) ) ) GROUP BY GLPD.GLDGL, GLPGL.GLGLNM, cvtdate(GLPD.GLDEDT), GLPD.GLDJC, GLPD.GLDEDS, GLPD.GLDJB, GLPD.GLDCC, GLPD.GLDCN, GLPPJ.GLPJ, DT_ROLLUPLEV.XAFVVC, trim(GLPPJ.GLPJNM), GLPD.GLDBT, GLPD.GLDBE, GLPD.GLDBL
    Has anyone seen anything like this?
    We have recently migrated from BO XI R2 SP2 to BO XI R2 SP5.
    We use SQL Server 2005 SP3.

    This should be set up in steps, Have you configured java AD kerberos so you can login via your web/app with AD? This is a prerequisite before setting up any type of delegation to the DB.
    You can also set up SSO in the front end but this shouldn't be necessarry for delegating to the DB.
    What SPN's do you need...
    Well if using java AD you should have an SPN for the account running the SIA (typically BOBJCentralMS/something) This SPN needs to be set in the CMC, You will need the krb5 and bsclogin files to login to your web/app with kerberos/AD. The krb5.ini will have to have a setting forwardable = true, and finally the MSAS server will need SPN's http://support.microsoft.com/kb/917409
    This a a very complex configuration and you will likely need to open an incident with support to get an engineer to help. I'm not sure where our current docs for the configuration are.
    Regards,
    Tim

  • Dynamic SQL Joining between tables and Primary keys being configured within master tables

    Team , Thanks for your help in advance !
    I'm looking out to code a dynamic SQL which should refer Master tables for table names and Primary keys and then Join for insertion into target tables .
    EG:
    INSERT INTO HUB.dbo.lp_order
    SELECT *
    FROM del.dbo.lp_order t1
    where not exists ( select *
    from hub.dbo.lp_order tw
    where t1.order_id = t2.order_id )
    SET @rows = @@ROWCOUNT
    PRINT 'Table: lp_order; Inserted Records: '+ Cast(@rows AS VARCHAR)
    -- Please note Databse names are going to remain the same but table names and join conditions on keys
    -- should vary for each table(s) being configured in master tables
    Sample of Master configuration tables with table info and PK Info :
    Table Info         
    Table_info_ID    Table_Name    
    1        lp_order    
    7        lp__transition_record    
    Table_PK_Info        
    Table_PK_Info_ID    Table_info_ID    PK_Column_Name
    2                1    order_id
    8                7    transition_record_id
    There can be more than one join condition for each table
    Thanks you !
    Rajkumar Yelugu

    Hi Rajkumar,
    It is glad to hear that you figured the question out by yourself.
    There's a flaw with your while loop in your sample code, just in case you hadn't noticed that, please see below.
    --In this case, it goes to infinite loop
    DECLARE @T TABLE(ID INT)
    INSERT INTO @T VALUES(1),(3),(2)
    DECLARE @ID INT
    SELECT @ID = MIN(ID) FROM @T
    WHILE @ID IS NOT NULL
    PRINT @ID
    SELECT @ID =ID FROM @T WHERE ID > @ID
    So a cursor would be the appropriate option in your case, please reference below.
    DECLARE @Table_Info TABLE
    Table_info_ID INT,
    Table_Name VARCHAR(99)
    INSERT INTO @Table_Info VALUES(1,'lp_order'),(7,'lp__transition_record');
    DECLARE @Table_PK_Info TABLE
    Table_PK_Info_ID INT,
    Table_info_ID INT,
    PK_Column_Name VARCHAR(99)
    INSERT INTO @Table_PK_Info VALUES(2,1,'order_id'),(8,7,'transition_record_id'),(3,1,'order_id2')
    DECLARE @SQL NVarchar(MAX),
    @ID INT,
    @Table_Name VARCHAR(20),
    @whereCondition VARCHAR(99)
    DECLARE cur_Tabel_Info CURSOR
    FOR SELECT Table_info_ID,Table_Name FROM @Table_Info
    OPEN cur_Tabel_Info
    FETCH NEXT FROM cur_Tabel_Info
    INTO @ID, @Table_Name
    WHILE @@FETCH_STATUS = 0
    BEGIN
    SELECT @whereCondition =ISNULL(@whereCondition+' AND ','') +'t1.'+PK_Column_Name+'='+'t2.'+PK_Column_Name FROM @Table_PK_Info WHERE Table_info_ID=@ID
    SET @SQL = 'INSERT INTO hub.dbo.'+@Table_Name+'
    SELECT * FROM del.dbo.'+@Table_Name+' AS T1
    WHERE NOT EXISTS (
    SELECT *
    FROM hub.dbo.'+@Table_Name+' AS T2
    WHERE '+@whereCondition+')'
    SELECT @SQL
    --EXEC(@SQL)
    SET @whereCondition = NULL
    FETCH NEXT FROM cur_Tabel_Info
    INTO @ID, @Table_Name
    END
    Supposing you had noticed and fixed the flaw, your answer sharing is always welcome.
    If you have any question, feel free to let me know.
    Eric Zhang
    TechNet Community Support

  • SQL Join help for multiple values in single field.

    Hello All,
    I need a help, I have two tables T1 and T2
    Content of T2 will be like
    T2. ID | T2.USERNAME
    ID1 | John
    ID2 | Peter
    ID3 | Mark
    Content of T1 is like
    T1.ID
    ID1 ID2 ID3
    ID2
    ID1 ID3
    I need to join these two tables and replace the T1.ID values with T2.USERNAME, for eg. Row one of T1 should be changed as John Peter Mark.
    Note: ID1 ID2 ID3 is a single value.
    Thanks for your help.
    Sathish.

    At Volder: I have made a slight enhancement. It's the same thing but the other way around as last week's regular expression thread. Remember the "and then the bird flew away"? ;-)
    SQL> create table t1
      2  as
      3  select 'ID1 ID2 ID3' id from dual union all
      4  select 'ID2' from dual union all
      5  select 'ID1 ID3' from dual union all
      6  select 'ID11 ID2' from dual
      7  /
    Tabel is aangemaakt.
    SQL> create table t2
      2  as
      3  select 'ID1' id, 'John' username from dual union all
      4  select 'ID2', 'Peter' from dual union all
      5  select 'ID3', 'Mark' from dual union all
      6  select 'ID11', 'Volder' from dual
      7  /
    Tabel is aangemaakt.
    SQL> select * from t1
      2   model
      3    reference r on (select t2.*, rownum rn from t2)
      4     dimension by (rn)
      5     measures(id, username)
      6    main m
      7     dimension by (id)
      8     measures(cast(id as varchar(200)) str)
      9     rules iterate(100) until (r.id[iteration_number+1] is null)
    10      (str[any] = replace(str[CV()], r.id[iteration_number+1],r.username[iteration_number+1]))
    11  /
    ID          STR
    ID1 ID2 ID3 John Peter Mark
    ID2         Peter
    ID1 ID3     John Mark
    ID11 ID2    John1 Peter
    4 rijen zijn geselecteerd.
    SQL> select id
      2       , str
      3    from t1
      4   model
      5         reference r on (select id,username,rownum rn from t2)
      6           dimension by (rn)
      7           measures (id, username)
      8         main m
      9           dimension by (id)
    10           measures (cast(' ' || id || ' ' as varchar2(200)) str)
    11           rules iterate(1000) until (r.id[iteration_number+1] is null)
    12           ( str[any] = replace
    13             ( str[cv()]
    14             , ' ' || r.id[iteration_number+1] || ' '
    15             , ' ' || r.username[iteration_number+1] || ' '
    16             )
    17           )
    18  /
    ID          STR
    ID1 ID2 ID3  John Peter Mark
    ID2          Peter
    ID1 ID3      John Mark
    ID11 ID2     Volder Peter
    4 rijen zijn geselecteerd.At Sathish: just look at the queries we have to come up with to do such a simple thing. As said many times before, I would also encourage you to change the design instead of executing the queries presented by Volder and me.
    Regards,
    Rob.
    Message was edited by:
    Rob van Wijk
    Just noticed I missed a final TRIM function around "str", so please add this.

  • Using delete in SQL Joins

    What is wrong in this query am getting incorrect syntax near ','.error.I am using sql server 2014
    DELETE ab, b
    FROM Authors AS a INNER JOIN AuthorArticle AS ab ON a.AuthID=ab.AuthID
    INNER JOIN Articles AS b ON ab.ArticleID=b.ArticleID
    WHERE AuthorLastName='Tom';

    What is wrong in this query am getting incorrect syntax near ','.error.I am using sql server 2014
    DELETE ab, b
    FROM Authors AS a INNER JOIN AuthorArticle AS ab ON a.AuthID=ab.AuthID
    INNER JOIN Articles AS b ON ab.ArticleID=b.ArticleID
    WHERE AuthorLastName='Tom';
     you cannot delete multiple table rows using a single delete command... you need either separate delete commands - each for one table  or better go with foreign key set up and on delete cascade.
    refer : http://blog.sqlauthority.com/2012/09/27/sql-server-not-possible-delete-from-multiple-table-update-multiple-table-in-single-statement/
    Hope it Helps!!

  • SQL join clauses in JSP

    We want to make an edit in which users will be able to write SQL queries and show them the result in a table. The problem is that, when doing joins, the fields with the same name in both database tables are misinterpreted, for example:
    if we have x.name and y.name as columns of two tables (x and y), when we use getString("name") we lose the string for the second getString.
    We have tried too:
    getString(rsmd.getTableName(i)+".name") being rsmd a ResultSetMetaData object and i the number of the column. It wasn't successful because getTableName didn't return the table name (as we know, it returns the table name or "" if not applicable).
    thanks in advance.

    Is this getString("name") method used over object "Resultset" ??
    U can use getString(int) instead and specify the location of the "name" attributes
    Example if the SQl looks like
    select x.name,y.name,x.abc,x.temp form ... bla bla
    x.name is getString(1);
    y.name is getString(2);
    Hope this helped you
    Thanks
    Sampath .

  • SQL Joins & joining 4 tables help.

    Post Author: n8than1
    CA Forum: Data Connectivity and SQL
    Hello,  I'm trying to build a report to show orders shipped, and pull in costing information from my sales tables.  I have 4 tables I'm using data from, and I'm linking my shipping master and shipping items tables by a left outer join on shipper number.  I'm linking my sales master table and sales item table using a left outer join on sales order number.  Now I need to link the 4 tables together, and everything I try spits out duplicate line items. I'm linking my shipping master table to sales order master using a inner join on sales order number. here is a copy of my query: SELECT "sorels"."fmatlcost", "sorels"."fsetupcost", "sorels"."flabcost", "sorels"."fovhdcost", "sorels"."forderqty", "shmast"."fshipdate", "shitem"."fshipqty", "shitem"."fpartno", "somast"."fusercode", "shmast"."fcbcompany" FROM   (("<SQL Database>"."dbo"."somast" "somast" INNER JOIN "<SQL Database>"."dbo"."shmast" "shmast" ON "somast"."fsono"="shmast"."fcsono") LEFT OUTER JOIN "<SQL Database>"."dbo"."sorels" "sorels" ON "somast"."fsono"="sorels"."fsono") LEFT OUTER JOIN "<SQL Database>"."dbo"."shitem" "shitem" ON "shmast"."fshipno"="shitem"."fshipno" WHERE  ("shmast"."fshipdate">={ts '2007-11-01 00:00:00'} AND "shmast"."fshipdate"<{ts '2007-11-30 00:00:01'}) AND "shitem"."fpartno" NOT  LIKE 'PM%' ORDER BY "somast"."fusercode", "shmast"."fcbcompany"

    Post Author: GraemeG
    CA Forum: Data Connectivity and SQL
    At a glance, the problem seems to be primarily that you are not giving enopugh information to your joins to limit the data displayed. If you added an order and shipment line number to the joins this may help. Just for fun, can you put the table structures here and I'll give it a whirl? Alternatively, email me a sample from all four tables and I'll put something together and send it back. Use graemeg AT falum DOT co DOT nz.
    Cheers G

Maybe you are looking for

  • Error while posting INvoice in MIRO *** URGENT****

    Hi, System is not allowing me to save an invoice in MIRO which says Reference date and Asset value date in the LINE ITEM are not in date format "//--" though we have left thefields as dafault (and have entered nothing there). These fields are filled

  • Set up a family with Apple Products

    What is the best way to set up a family with multiple apple products? Equipment: My wife and I each have iPhone v4s We have an AppleTV version 1 and an AppleTV version 2 iPad 2 NAS in the closet with iTunes server (which we don't utilize) iTunes inst

  • How to remove credit card information

    hi so my mum has been on my account and without me knowing put her credit card information onto billing information. Now it is asking for sedurity code and all sorts of things and now i cant sync my phone to my account, i dont want to create a new ac

  • Transfer info from Ibook G4 10.3.9 to new MacBook Pro

    Hi How do I transfer files from my Ibook G4 10.3.9 to a new MacBook Pro? There is no migration assistant on 10.3.9. I have tried a firewire cable but it doesn't recognise the old computer. Help appreciated. Thanks Kay

  • Production conformation report

    Hi experts, Pls give me support how to create production report on regarding pattern plant     date     production     transfer        dispatch       stock waiting for your reply