problem with join of two tables

Hi, consider the following data
WITH data AS
(
  SELECT 123 cid, 'aaa' isi, 'kkk' sud, 'ttt' ri FROM dual UNION ALL 
  SELECT 222 cid, 'bbb' isi, 'gggg' sud, 'hhh' ri FROM dual

) ,
data2 AS 
(
  SELECT 'aaa' isi, 'yyy' sud, 'ooo' ri FROM dual UNION ALL 
  SELECT 'qqq' isi, 'ggg' sud, 'ooo' ri FROM dual UNION ALL 
  SELECT 'uuu' isi, 'ppp' sud, 'ttt' ri FROM dual UNION ALL
   SELECT 'ppp' isi, 'mmm' sud, 'nnn' ri FROM dual 


)
what I want to do, is to join data2 with data by isi, ri or southern id table and produce this output.
 cid  txt
 ===  ====
 123  aaa
 222  ggg
 123  ttt
It's how I got the above output:
first try to join isi in database2 with isi in "features" and discover if line matches. If this is the case, display the cid of the data table and the use of the value to match.
e.g. in the first line of table data2, we can see that isi = aaa matches line an isi data table. If the output displays 123 and value aaa.

If the rank table two of the Data2 isi = qqq. When join them with the data table, we find not all isi with qqq. in this case, it must join with column of South. We can see that South = ggg data2 games
the second line in the table of output so will bee 222 and value ggg.

now, take a look at the third row in Database2. ISI = uuu is not found in the data table when join them. then try to join to the South. South = ttt is also not found in any row of the data table. so join with ri. We
can see that ri = ttt data2 matches with ri = ttt in the table of data online 1. Therefore, we display the value.

can someone help me write a sql query that joins these two tables by isi. If no line found then join South, if no found rows then join in ri? Thank you

Hello

elmasduro wrote:
Hi Frank, data2.sud = 'Gay' (4 characters) assume to be South = "ggg". by mistake, I type extra g.

I have another question about the request. What happens if I want to bring rows of data.2 even if they do not exist in the data table for the entire column was join?
for example, I want to show this:

cid  txt
===  ====
123  aaa
222  ggg
123  ttt
ppp  --row from data2

the columns of the last row of data.2 does not match any column in the data table. in this case, I want to make but cid will be null. I tried outer join on your request, but it looks like I can not clause or with outer join

SELECT     d1.cid
,     CASE
          WHEN  d1.isi = d2.isi  THEN  d2.isi
          WHEN  d1.sud = d2.sud  THEN  d2.sud
                                        ELSE  d2.ri
     END     AS txt
FROM data     d1
JOIN     data2     d2  ON     d1.is(+)i     = d2.isi
              OR     d1.sud(+)     = d2.sud
              OR     d1.ri(+)     = d2.ri
;

How can I re - write the query for this case? Thanks again for your help

Here is the outer join syntax:

SELECT     d1.cid
,     CASE
          WHEN  d1.isi = d2.isi  THEN  d2.isi
          WHEN  d1.sud = d2.sud  THEN  d2.sud
          WHEN  d1.ri  = d2.ri   THEN  d2.ri
                                        ELSE  d2.isi
     END     AS txt
FROM          data2     d2
LEFT OUTER JOIN     data     d1  ON     d1.isi     = d2.isi
                       OR     d1.sud     = d2.sud
                       OR     d1.ri     = d2.ri
;

The + sign for outer joins only works with the old join syntax, non-ANSI. Do not try to mix the two different ways to do joins.

Not to mention that the outer join, don't forget to change the CASE expression, to include the new possibility of any columns 3 join matching.

Tags: Database

Similar Questions

  • Is there a problem with ValueChangeListener and af: table?

    Hello...

    I use JDeveloper 11.1.2.0.0

    Is there a problem with ValueChangeListener and af: table.

    Here my problem...

    I have two inputtext in af:table and I want to change the value of inputtext2 when I change the value of inputtext1
    so I put the autosubmit = "true" to inputtext1 and set the valuechangelistener method that is in the page bean
    and I put the partial inputtext2 trigger = "inputtext1 id".

    but when I run the page and change the value of inputtext1 that nothing happens.

    But if I have the previous scenario in af:panelFormLayout instead of af: table its work and the value of inputtext2 is changed to the user.

    any ideas...

    Thans.

    Sorry for the delay... :(

    And why if I use page JSF is the binding property disappears
    in the tab advanced in the property inspector.

    If you cannot power discovered the binding property in the palette of the means, your jsff page is automatically linked.
    If only the problem.

    try to create the new page jsff, while creating jsff, finally there is radio box something like
    do not expose the UI components automatically. check and create.

    and create a java file. Then you can bind components with the java file as you wish.

    to check your jsff page is autobinded are no means?
    Open your jsff page.

    Menu's that are on it - in this section. You can see the design menu that struck. If you hit it means you see Wizard property page go to the tab component binding
    There is a check box available

    If the box is ticked means that you page are automatically linked. If this isn't the case, you must link.

    -edited lately.

  • problem with join

    Hello Experts,

    I'm having a little problem with joining me. its not taking the values that should be
    declare
    l_start_file_name varchar2(50) := 'liab_report_summary_p008_c';
    l_end_file_name varchar2(50)   := '_english.rep';
    l_file_name varchar2(100);
    l_sql varchar(32767);
    refresh_cdc varchar2(10) := '00540';
    
    Begin
    
    l_file_name := l_start_file_name||REFRESH_CDC||l_end_file_name;
    
     l_sql := 'create or replace directory GTECHFILES as ''/ftpfiles/gtechfiles/acct_'||REFRESH_CDC||'''';
      execute immediate l_sql;
    
    
    l_sql :=  ' CREATE TABLE LOTO_LIABILITY_REPORT_temp             '||
              ' (                                                   '||
              '  draw_number       varchar2(50),                    '||
              '  total_winners_amt number,                          '||
              '  paid_today_amt    number,                          '||
              '  total_paid_amt    number,                          '||
              '  expired_today_amt number,                          '||
              '  total_expired_amt number,                          '||
              '  frac_round_amt    number,                          '||
              '  outstanding_amt   number                           '||
              ' )                                                   '||
              ' ORGANIZATION EXTERNAL                               '||
              '   (  TYPE ORACLE_LOADER                             '||
              '     DEFAULT DIRECTORY GTECHFILES                    '||
              '     ACCESS PARAMETERS                               '||
              '       (                                             '||
              '      RECORDS DELIMITED BY NEWLINE                   '||
              '    BADFILE TEMPDIR:''loto_liability_report.bad''    '||
              '    DISCARDFILE TEMPDIR:''loto_liability_report.dis'''||
              '    LOGFILE TEMPDIR:''loto_liability_report.log''    '||
              '      SKIP 8                                         '||    
              '      FIELDS LDRTRIM                                 '||
              '      MISSING FIELD VALUES ARE NULL                  '||
              '       (                                             '||
              '  draw_number       (1:11)  char(11),                '||
              '  total_winners_amt (14:24) char(11),                '||
              '  paid_today_amt    (26:36) char(11),                '||
              '  total_paid_amt    (38:48) char(11),                '||
              '  expired_today_amt (50:60) char(11),                '||
              '  total_expired_amt (62:72) char(11),                '||
              '  frac_round_amt    (74:80) char(7),                 '||
              '  outstanding_amt   (82:92) char(11)                 '||
              '       )                                             '||
              '   )                                                 '||
              '     LOCATION ('''||l_file_name||''')                '||
              ' )                                                   '||
              ' REJECT LIMIT UNLIMITED                              '||
              ' NOPARALLEL                                          '||
              ' NOMONITORING                                        ';
    
             execute immediate l_sql; 
    
    
     l_sql := ' insert into LOTO_LIABILITY_REPORT '||
     ' ( draw_number             , '||
     '   total_winners_amt       , '||
     '   paid_today_amt          , '||
     '   total_paid_amt          , '||
     '   expired_today_amt       , '||
     '   total_expired_amt       , '||
     '   frac_round_amt          , '||
     '   outstanding_amt         , '||
     '   source                  , '||
     '   inserted_DATE           , '||
     '   CDC                     , '||
     '   draw_start_date         , '||
     '   draw_end_date             '||
     ' )                           '||
     '   SELECT                    '||
     '       a.to_number(substr(draw_number,1,instr(draw_number,''/'',1)-1)) , '||
     '       a.total_winners_amt                                             , '||
     '       a.paid_today_amt                                                , '||
     '       a.total_paid_amt                                                , '||
     '       a.expired_today_amt                                             , '||
     '       a.total_expired_amt                                             , '||
     '       a.frac_round_amt                                                , '|| 
     '       a.outstanding_amt                                               , '||  
     '       '''||l_file_name                                           ||''', '||
     '       sysdate                                                         , '||
     '       '''||refresh_cdc                                           ||''', '|| 
     '       b.start_date                                                    , '|| 
     '       b.end_date                                                        '|| 
     '    FROM                                                                 '||
     '       a.LOTO_LIABILITY_REPORT_temp                                     ,'||
     '       b.draws                                                           '||
     '    where                                                                '||
     '       a.draw_number is not null                                         '||
     '    and                                                                  '||
     '       a.total_winners_amt is not null                                   '||
     '    and                                                                  '|| 
     '       a.to_number(substr(draw_number,1,instr(draw_number,''/'',1)-1))= b.num ';
    
     
        dbms_output.put_line(l_sql);
             execute immediate l_sql;           
             
    l_sql :='drop table LOTO_LIABILITY_REPORT_temp';
     
            execute immediate l_sql;
            
    exception
    when others then
    rollback;
    l_sql :='drop table LOTO_LIABILITY_REPORT_temp';
    execute immediate l_sql;
    debug_message('LOTO_LIABILITY_REPORT_temp_UPLOAD/'||REFRESH_CDC,'Unexpected Error '||sqlerrm);
    END LOTO_LIABILITY_REPORT;

    at least

     '    FROM                                                                 '||
     '       LOTO_LIABILITY_REPORT_temp a                                     ,'||
     '       draws b                                                           '||
     '    where                                                                '||
    

    Concerning

    Etbin

  • How it warns Oracle to use an index for the join of two tables...

    How to prevent the Oracle to use an index for the join of two tables to get a view online that is used in an update statement?

    O.K. I think I should explain what I mean:

    When you join two tables that have many entries sometimes there're better is not to use an index on the column that is used as a criterion to join.

    I have two tables: table A and table B.

    Table A has 4,000,000 entries and table B has 700,000 entries.

    I have a join of two tables with a numeric column as join criteria.

    There is an index on this column in A table.

    So I instead of
      where (A.col = B.col)
    I want to use
      where (A.col+0 = B.col)
    in order to avoid Oracle using the index.

    When I use the join in a select query, it works.

    But when I use the join as inline in an update statement I get the error ORA-01779.

    When I remove the '+ 0' the update statement works. (The column is unique in table B).

    Any ideas why this happens?

    Thank you very much in advance for any help.

    Hartmut cordially

    You plan to use a NO_INDEX hint as shown here: http://www.psoug.org/reference/hints.html

  • Join of two tables in two different schemas

    Hi all

    I have an obligation to join two tables on two different schemas. How to join these two tables in the object view.

    Thanks in advance.

    Concerning
    Kaushik Guillaumin

    You can do just that using schema name in the +' view object.table name ' + according to the query object and also grant select the another schema to this schema user

    ex
    you need schem is test and another Act you need to a view object based on the test to join a table on shcema Act

    you write semply object sql view code:

    Act.table name

    and you can also give him select statement on Bill schem table to test

    concerning

  • Unique problem with selction on the table (Query Page)

    Unique problem with selction on the table (Query Page)

    I have a VO data Bulletin Board, with a transitional attribute for selction unique column.
    My requirement is that I need to identify the line that was selected in the table.

    I associated with fireAction singleSelection column, such that whenever the user selects the line
    I'm looking for that VO using some rowIterator.
    But when running the loop of the transient VO that is mapped to the singleSelection variable is the show as "n" / NUll
    for all the lines...

    So how do you identify the selected line in singleSelection to a table.

    -Sasi

    In the property inspector of the element for which you've put firePartialAction, you can find a property named "parameters". That mention primary key as your setting.

    You can get the arameter using pageContext.getparameter ();

    -Anand

  • The two problems with sub form of table, associated with check boxes

    Hi all -
    Jari already helped me thereby once last week, but I'm running into some new questions.

    http://Apex.Oracle.com/i/index.html
    workspace: Leppard
    username: Guest
    PW: app_1000
    Application: MyTestApp

    Maybe I need to split these into two questions, if so just let me know.

    Question 1: On the first tab (tab 1 report) I have a simple tabular presentation based on the EMP table. The column of the box on the far right, when checked restores the Ename column readonly. The problem is that it only works one way. Unchecking the checkbox is not cancel the read-only.

    It is javascript code that I have on the page:
    function test(pThis) {
     //get the current row index on change
     var currIndex = $('input[name="'+pThis.name+'"]').index(pThis);
    
     // check current items value (return value of lov)
     if (pThis.value=='Y') {
      $('input[name="f02"]')[currIndex].style.backgroundColor = "LightGrey";
      $('input[name="f02"]')[currIndex].readOnly=true;
    }
    else if (pThis.value=='N') {
      $('input[name="f02"]')[currIndex].style.backgroundColor = "Red";
      $('input[name="f02"]')[currIndex].readOnly=false;
    }
    }
    The attribute of the element on the checkbox column is
    onClick="javascript:test(this);" 
    (It seems to work although I use onClick or onChange so I don't know if that makes a difference).

    But the main problem is that the code does not recognize the value of "n" in the column. I checked with firebug and columns I have untick are definitely on 'n', but I can't get javascript code to recognize this value. Even if I take the "ElseIf" code and just change the first part to (pThis.value ==' no) still does not work. There seems to be something with the value "n" recognize themselves do not, but I can not understand.

    Question 2: on the second tab - tab report 2. The same report but this time, I use a javascript character counter similar to that described in the sample application of the Dene (page 276 > http://apex.oracle.com/pls/otn/f?p=31517:276:19207673535900:NO). The counter of characters on the Ename field include javascript and an expression of HTML on the Ename column. The counter works fine, but now, the javascript code to make the column readonly work over all.

    Any ideas on these are much appreciated!

    Thanks in advance,
    John


    • Please please understand what HTML is generated and how to inspect. Once you do this, you can easily eliminate many problems with selectors not seeming to work. A text box is not an input for example element.
    • Boxes rely on the checked, not the value property. Apex circumvents this by creating a hidden extra element which will get the value based on the checked property of the visible checkbox
    • Do not use these horrible onchange and onclick attributes :( Use a dynamic action or jQuery to bind events.
    • Do not apply a style via javascript. Use CSS for this drive as with jQuery, you can easily add, remove, or toggle the classes too. And if you know jQuery selectors, you can understand css selectors because they are substantially the same.
    • I don't know why people insist on using rowIndex or substringing ID. I find it unnecessary and more complex that the alternative (crosses with jQuery)
    • The difficulty also in things into action through pagination. Running on just the visible page it of a trifle, but through paging requires more work than just check "fire on loading the page" is not enough. I'm sure you'd want your ENAME either red or gray column and readonly as soon as the page is loaded, and not when you start typing in the box...

    Form 1 tab: copied to Page 12 and made my changes here:_


    • OnChange on ENAME. This removed. No idea why you would need it there seems a crutch for not having the field in the desired state when the page is loaded.
    • OnClick on CHECKBOX. Removed what I hate these attributes. Replaced by a dynamic action.
    • Dynamic action "checkbox: ENAME readonly value."

      • Event: After refresh
      • Selection type: region
      • Region: Form of tab 1
      • No condition
      • Scope of the event: static
      • Real Action

        • Run the JavaScript Code
        • Fire on loading the Page: YES
        • Code:

          //at page load and after each region refresh:
          //each: check all checkboxes and set readonly on ename accordingly
          //click: when the checkbox changes, change ename accordingly
          $("td[headers='CHECKBOX'] input[type='checkbox']:visible")
          .each(function(){checkReadonly(this);})
          .click(function(){checkReadonly(this);});
          



  • Page > function and global variables declaration

    function checkReadonly(pCheck){
       var lCheck = $(pCheck);
       lCheck.closest("tr")
       .find("td[headers='ENAME'] input:visible").each(function(){
          $(this).prop("readonly", lCheck.prop("checked"));
       });
    };
    

  • Page > CSS Inline

    td[headers='ENAME'] input{
    background-color: red;
    }
    td[headers='ENAME'] input[readonly]{
    background-color: lightgrey;
    }
    

    CSS works so much better for this than the application of style through js...

  • Form 2 tab: copied to Page 13 and made my changes here:_


    • OnChange on ENAME. This removed. No idea why you would need this.
    • OnClick on CHECKBOX. Removed what I hate these attributes. Replaced by a dynamic action.
    • Dynamic action: identical to page 12, just modified trigger area
    • Changed input to TEXTAREA when it is required:
    • Page > function and global variables declaration

      function checkReadonly(pCheck){
         var lCheck = $(pCheck);
         lCheck.closest("tr")
         .find("td[headers='ENAME'] textarea:visible").each(function(){
            $(this).prop("readonly", lCheck.prop("checked"));
         });
      };
      

    • Page > CSS Inline

      td[headers='ENAME'] textarea{
      background-color: red;
      }
      td[headers='ENAME'] textarea[readonly]{
      background-color: lightgrey;
      }
      

    • The f_set_counter function, I changed a bit: there are 2 straps too, put a semicolon at the end of each line.
      -Change $x (node) .value $s (node, value) and $v (node)
      -changed $x (node) .innerHTML to $(node) .text)
      I know: it worked. I like this better. OCD? :/

    function f_set_counter(pThis,pLength,pMaxLength,pReset)
    {
       if (pLength>pMaxLength){
          alert('The maximum length of '+pMaxLength+' exceeded.');
          $s(pReset, $v(pReset).substring(0,pMaxLength));
          $("#"+pThis).text(pMaxLength);
       }else{
          $("#"+pThis).text(pLength);
       };
    };
    

    Published by: Tom on February 15, 2013 12:48
    Made a mistake in the case of dynamic action :->, click after refresh!

  • Problem with joining several tables

    Hello PL/SQL gurus and experts.

    I use Oracle Database 11 g Enterprise Edition Release 11.2.0.1.0 - 64-bit Production version
    I followed two tables

    Student-
    drop table TT3;
    create table TT3(FeesCntlr,CommCntlr,LatePayCntlr,Name,Age) as select
    1,11,21,'Mike',25 from dual union all select
    2,12,22,'Clark',26 from dual union all select
    1,11,21,'Mike',27 from dual union all select
    4,17,27,'Ussan',28 from dual union all select
    5,13,21,'Linda',29 from dual union all select
    6,14,24,'Obrek',35 from dual union all select
    7,15,25,'Batty',45 from dual union all select
    8,16,26,'Nicky',38 from dual union all select
    1,11,21,'Mike',25 from dual union all select
    2,12,22,'Clark',26 from dual union all select
    1,11,21,'Mike',27 from dual union all select
    4,17,27,'Ussan',28 from dual union all select
    5,13,21,'Linda',29 from dual union all select
    6,14,24,'Obrek',35 from dual union all select
    7,15,25,'Batty',45 from dual union all select
    8,16,26,'Nicky',38 from dual ;
    Fees-
    drop table TT4;
    create table TT4(FeesCntlr,CommCntlr,LatePayCntlr,Fees,Commission,Latepayment) as select
    1,11,21,25000,4456,223 from dual union all select
    2,12,22,356000,3321,0 from dual union all select
    1,11,21,456000,223,33 from dual union all select
    4,17,27,32890,0,0 from dual union all select
    5,13,21,0,778,223 from dual union all select
    6,14,24,332567,222,0 from dual union all select
    7,15,25,228990,22,0 from dual union all select
    8,16,26,0,0,2234 from dual union all select
    1,11,21,22345,0,0 from dual union all select
    2,12,22,2222789,2,33 from dual union all select
    1,11,21,334567,0,0 from dual union all select
    4,17,27,9987250,2,33 from dual union all select
    5,13,21,2227890,0,0 from dual union all select
    6,14,24,2278231,0,3345 from dual union all select
    7,15,25,223456,2,0 from dual union all select
    8,16,26,223890,0,0 from dual ;
    I am looking forward to the fees, commissions and surcharges output for each student and by using the following SQL code.
    select t3.Name,t3.age,t4.Fees
    from tt3 t3, tt4 t4
    where t3.FeesCntlr=t4.FeesCntlr
    union
    select t3.Name,t3.age,t4.Commission
    from tt3 t3, tt4 t4
    where t3.CommCntlr=t4.CommCntlr
    union
    select t3.Name,t3.age,t4.Latepayment
    from tt3 t3, tt4 t4
    where t3.LatePayCntlr=t4.LatePayCntlr
    but it gives me not the correct result and showing a lot of entries and display only the "Expenses" column then only I'm looking for the output to be -
    Name     Age     Fees          Commission     Laypayment
    Mike     25     837912          4679          256
    Clark     26     2578789          3323          33
    Ussan     36     10020140     2          33
    Linda     38     2227890          778          223
    Obrek     38     2610798          222          3345
    Batty     32     452446          24          0
    Nicky     23     223890          0          2234
    Kindly help me with this. Thank you in advance for your time and effort.

    Hello

    I see your table TT3 has duplicated lines. A reason for this?

    Rather than run a separate, I created it without duplicated lines:

    create table TT3(FeesCntlr,CommCntlr,LatePayCntlr,Name,Age) as select
    1,11,21,'Mike',25 from dual union all select
    2,12,22,'Clark',26 from dual union all select
    4,17,27,'Ussan',28 from dual union all select
    5,13,21,'Linda',29 from dual union all select
    6,14,24,'Obrek',35 from dual union all select
    7,15,25,'Batty',45 from dual union all select
    8,16,26,'Nicky',38 from dual;
    
    create table TT4(FeesCntlr,CommCntlr,LatePayCntlr,Fees,Commission,Latepayment) as select
    1,11,21,25000,4456,223 from dual union all select
    2,12,22,356000,3321,0 from dual union all select
    1,11,21,456000,223,33 from dual union all select
    4,17,27,32890,0,0 from dual union all select
    5,13,21,0,778,223 from dual union all select
    6,14,24,332567,222,0 from dual union all select
    7,15,25,228990,22,0 from dual union all select
    8,16,26,0,0,2234 from dual union all select
    1,11,21,22345,0,0 from dual union all select
    2,12,22,2222789,2,33 from dual union all select
    1,11,21,334567,0,0 from dual union all select
    4,17,27,9987250,2,33 from dual union all select
    5,13,21,2227890,0,0 from dual union all select
    6,14,24,2278231,0,3345 from dual union all select
    7,15,25,223456,2,0 from dual union all select
    8,16,26,223890,0,0 from dual ;
    
      SELECT t3.name, t3.age, SUM (t4.fees) fees, SUM (t4.commission) commission
           , SUM (t4.latepayment) latepayment
        FROM tt3 t3, tt4 t4
       WHERE     t3.feescntlr = t4.feescntlr
             AND t3.commcntlr = t4.commcntlr
             AND t3.latepaycntlr = t4.latepaycntlr
    GROUP BY t3.name, t3.age;
    
    Output:
    NAME         AGE       FEES COMMISSION LATEPAYMENT
    ----- ---------- ---------- ---------- -----------
    Mike          25     837912       4679         256
    Ussan         28   10020140          2          33
    Linda         29    2227890        778         223
    Clark         26    2578789       3323          33
    Obrek         35    2610798        222        3345
    Nicky         38     223890          0        2234
    Batty         45     452446         24           0
    

    Kind regards.
    Al

    Published by: Alberto Faenza on November 6, 2012 12:40

  • help the join of two tables

    Hello

    I need your help in the script below:

    I have two tables.

    My "table1" table contains the data below:

    Code:

    Name, Value
    ------------
    12 A, 1
    12 B, 1
    12 C, 1



    Table2 contains the following data:

    Code:

    value, result
    ------------
    1.12
    1.24
    1.56
    1 423
    1.32
    1, 3




    I need to join based on a field value.

    My result is:

    Code:


    NAME, VALUE, RESULT
    -------------------------
    12 A, 1, 12
    12 B, 1: 24
    12 C, 1, 56
    12d, 1, 423
    12TH, 1, 32
    12F, 1, 3





    Based on the number of records in the second table, it must add A to Z at the end of the name field. The number of records exceeds no more than 26. How can we achieve this?


    _________________

    Thank you
    Pocard

    OK, now you give other useful information - that there always will be combinations of amounts in table2 to match values in table1. (It is difficult to help when you say the specs one both :-))

    But it is not easy, because the code should really try to consider all combinations and then 'choose the right' - it's easy for us humans, but not easy to code in the programming logic.
    I made an attempt:

    SQL> set linesize 120
    SQL> with table1 as (
      2     select 'A1' name, 123 id, 150 value from dual union all
      3     select 'A2' name, 123 id, 200 value from dual union all
      4     select 'A3' name, 123 id, 300 value from dual
      5  ), table2 as (
      6     select 123 id, 100 value from dual union all
      7     select 123 id, 100 value from dual union all
      8     select 123 id, 50  value from dual union all
      9     select 123 id, 100 value from dual union all
     10     select 123 id, 100 value from dual union all
     11     select 123 id, 100 value from dual union all
     12     select 123 id, 100 value from dual
     13  )
     14  --
     15  -- End of test data
     16  --
     17  select
     18  t1.id, t1.name, t1.value, t2.value,
     19  t1.rn, t1.minval, t1.maxval,
     20  t2.rn, t2.sumval
     21  from (
     22     select
     23     tab1.*,
     24     nvl(sum(tab1.value) over (
     25        partition by tab1.id
     26        order by tab1.rn
     27        rows between unbounded preceding and 1 preceding
     28     ),0) minval,
     29     sum(tab1.value) over (
     30        partition by tab1.id
     31        order by tab1.rn
     32        rows between unbounded preceding and current row
     33     ) maxval
     34     from (
     35        select
     36        table1.*,
     37        row_number() over (
     38           partition by table1.id
     39           order by table1.value desc
     40        ) rn
     41        from table1
     42     ) tab1
     43  ) t1
     44  join (
     45     select
     46     tab2.*,
     47     sum(tab2.value) over (
     48        partition by tab2.id
     49        order by tab2.rn
     50     ) sumval
     51     from (
     52        select
     53        table2.*,
     54        row_number() over (
     55           partition by table2.id
     56           order by table2.value desc
     57        ) rn
     58        from table2
     59     ) tab2
     60  ) t2
     61  on (t2.id = t1.id)
     62  where t2.sumval > t1.minval
     63  and t2.sumval <= t1.maxval
     64  order by
     65  t1.id,
     66  t1.rn,
     67  t2.rn
     68  ;
    
            ID NA      VALUE      VALUE         RN     MINVAL     MAXVAL         RN     SUMVAL
    ---------- -- ---------- ---------- ---------- ---------- ---------- ---------- ----------
           123 A3        300        100          1          0        300          1        100
           123 A3        300        100          1          0        300          2        200
           123 A3        300        100          1          0        300          3        300
           123 A2        200        100          2        300        500          4        400
           123 A2        200        100          2        300        500          5        500
           123 A1        150        100          3        500        650          6        600
           123 A1        150         50          3        500        650          7        650
    
    7 rows selected.
    

    It doesn't seem to work for your sample data, but it is much too simple a rule at work in general. My "rule" is simply of sorts data according to the value descending and adding up to what 'enough' of values have been added.

    Consider this example of data instead of this:

    SQL> with table1 as (
      2     select 'A1' name, 1 id, 100 value from dual union all
      3     select 'A2' name, 1 id, 200 value from dual union all
      4     select 'A3' name, 1 id, 300 value from dual union all
      5     select 'B1' name, 2 id, 100 value from dual union all
      6     select 'B2' name, 2 id, 200 value from dual
      7  ), table2 as (
      8     select 1 id, 25  value from dual union all
      9     select 1 id, 75  value from dual union all
     10     select 1 id, 50  value from dual union all
     11     select 1 id, 50  value from dual union all
     12     select 1 id, 175 value from dual union all
     13     select 1 id, 225 value from dual union all
     14     select 2 id, 25  value from dual union all
     15     select 2 id, 50  value from dual union all
     16     select 2 id, 75  value from dual union all
     17     select 2 id, 100 value from dual union all
     18     select 2 id, 50  value from dual
     19  )
     20  --
     21  -- End of test data
     22  --
     23  select
     24  t1.id, t1.name, t1.value, t2.value,
     25  t1.rn, t1.minval, t1.maxval,
     26  t2.rn, t2.sumval
     27  from (
     28     select
     29     tab1.*,
     30     nvl(sum(tab1.value) over (
     31        partition by tab1.id
     32        order by tab1.rn
     33        rows between unbounded preceding and 1 preceding
     34     ),0) minval,
     35     sum(tab1.value) over (
     36        partition by tab1.id
     37        order by tab1.rn
     38        rows between unbounded preceding and current row
     39     ) maxval
     40     from (
     41        select
     42        table1.*,
     43        row_number() over (
     44           partition by table1.id
     45           order by table1.value desc
     46        ) rn
     47        from table1
     48     ) tab1
     49  ) t1
     50  join (
     51     select
     52     tab2.*,
     53     sum(tab2.value) over (
     54        partition by tab2.id
     55        order by tab2.rn
     56     ) sumval
     57     from (
     58        select
     59        table2.*,
     60        row_number() over (
     61           partition by table2.id
     62           order by table2.value desc
     63        ) rn
     64        from table2
     65     ) tab2
     66  ) t2
     67  on (t2.id = t1.id)
     68  where t2.sumval > t1.minval
     69  and t2.sumval <= t1.maxval
     70  order by
     71  t1.id,
     72  t1.rn,
     73  t2.rn
     74  ;
    
            ID NA      VALUE      VALUE         RN     MINVAL     MAXVAL         RN     SUMVAL
    ---------- -- ---------- ---------- ---------- ---------- ---------- ---------- ----------
             1 A3        300        225          1          0        300          1        225
             1 A2        200        175          2        300        500          2        400
             1 A2        200         75          2        300        500          3        475
             1 A1        100         50          3        500        600          4        525
             1 A1        100         50          3        500        600          5        575
             1 A1        100         25          3        500        600          6        600
             2 B2        200        100          1          0        200          1        100
             2 B2        200         75          1          0        200          2        175
             2 B1        100         50          2        200        300          3        225
             2 B1        100         50          2        200        300          4        275
             2 B1        100         25          2        200        300          5        300
    
    11 rows selected.
    

    In this data set simple ranking by value won't work - it should have been A3: (225,75), A2: (175,25) and A1: (50.50).

    I can't really think of a reasonably easy way to do this in SQL only. Maybe using the clause TYPE would be possible, but not negligible. It is possible, it would be easier to solve this problem in PL/SQL in iterating through a few tables and intelligently to try different combinations, rather than creating all combinations in a huge piece of brute force SQL.

    I'm sorry, Pandeesh, but I can't think a solution easily.
    I might be able to do something, if I fiddled with the problem for a few days, but that would be beyond the scope of this forum. It would be a consultation of employment rather than a little help from the forum :-)

  • Please, help me to join of two tables?

    Hello..

    I'm using oracle 11g.

    I have two tables with below description

    1.esb_v_study_personnel

    study_code_alias varchar2,

    Site_ID number,

    role_at_site_level_desc varchar2

    2 esb_v_study_site

    study_code_alias varchar2

    Site_ID

    I'm counting the role_at_site_level_desc where it is'Monitor' or 'primary monitor'

    So I wrote the following query

    Select study_code_alias, site_id,.

    no_of_study_monitors (role_at_site_lvl_desc)

    esb_v_study_site_personnel

    study_code_alias IN & arg_trial_code

    role_at_site_lvl_desc in ()"Monitor" "Main screen"()

    Group of study_code_alias, study_site_id

    order by study_site_id

    using the above, I'm getting lines of 1617.

    but I want to map the resultant site_id

    esb_v_study_site with lines of 1647. If I want to get all the site_id in esb_v_study_site table mapping to above query.

    Can you guide me on this point.

    I tried with a left outer join, but still iam getting lines of 1617.

    Select study_code_alias,

    no_of_study_monitors (role_at_site_lvl_desc)

    esb_v_study_site_personnel

    study_code_alias IN & arg_trial_code

    role_at_site_lvl_desc in ()"Monitor" "Main screen"()

    Group of study_code_alias, study_site_id

    order of study_site_id) a

    LEFT OUTER JOIN

    ON a.trial_no = d.trial_no et a.study_site_id = d.study_site_id

    d.study_code_alias in & arg_trial_code

    Group by d.study_code_alias, d.study_site_id, a.no_of_study_monitors

    order by d.study_site_id

    Please help me on this?

    I'm not quite sure, because your query seems to us of small missing pieces. He was probably down during some copy & paste on this forum.

    I guess the reason is that the left join is performed after the group where the count on the column does not count NULL values that might be created by the outer join.

    Maybe you can start with the following query and give us the results and tell us if it is always wrong and what the outcome would be expected.

    example (not tested the syntax)

    select  d.study_code_alias
        ,d.site_id
       , count(a.role_at_site_lvl_desc) no_of_study_monitors
       , count(distinct a.role_at_site_lvl_desc) no2
       , count(*) no3
    from esb_v_study_site d
    left join esb_v_study_site_personnel a on a.trial_no=d.trial_no and a.study_site_id=d.study_site_id and a.role_at_site_lvl_desc in ('Field Monitor','Primary Monitor')
    where d.study_code_alias IN (&arg_trial_code)
    group by d.study_code_alias,d.study_site_id
    order by d.study_site_id;
    

    BTW: If you read the FAQ in the upper right corner, here, he said how well sql zip code search.

  • Problems with automatic expansion into table cells

    I have problems with a table in my form in LiveCycle Designer.  In the document below, "Field 1", I enter text and the cell remains the same size, with the additional text indicated by a '+' at the bottom right.  This is the format I want.

    However, when I enter more than one line of text in the indicated "lines problem" in the file, the cell automatically expands to fit the text.  It's something I want to happen... I would like to the "problem of the lines" to show the same format that "Field 1" in the document and the cell containing the same size of the user required to click on the '+' to display additional information. ".  The problem is, the disorder of cells expanded the rest of the form when I put additional information in, and I want to keep the cells in a table evenly the same size.

    Thanks for your help!  The file is here:

    https://Acrobat.com/#d=tdu1W9Xp3PgGXcGLMLwo8A

    Windows 7, Acrobat X Pro 10.0.0, LC 9.0.0.2

    If you insist on past this road, you can click on the cell you want to order and on the Layout tab, uncheck develop it to adapt to the checkbox in the height box.

    Paul

  • Join of two tables

    Hi all

    I have two tables - TableA and TableB

    I need all these records in TableA that have no matching records in TableB based on Key1, Key2, and Key3 and process them further.

    Can someone help pls?

    Hello 954475

    Try this:

    SELECT A.*

    FROM TableA A

    WHERE DOES NOT EXIST (SELECT 1

    FROM TableB B

    WHERE A.Key1 = B.Key1

    AND A.Key2 = B.Key2

    AND A.Key3 = B.Key3

    )

    ;

    I hope that helps!

  • Problems with slices in FW / tables in DW


    I created a template page in FW. I made the slices and exported. When to use it in DW to template use, I have problems with some parts of the page skin. I have a top, a navagation on the left and a main content area. When you change the main content area, it puts the gaps in the left navigation, break to the top of the page.

    Can anyone help? PLEASE, I BEG YOU.

    Thanks for the tips, I'll try that.

  • Select the problem with joined tables

    Hello everyone I have the following query
    SELECT 
        OBJEKTI.OBJEKAT_ID OBJEKAT_ID, 
        OBJEKTI.ADRESA ADRESA, 
        OBJEKTI.POVRSINA POVRSINA, 
        OBJEKTI.BROJ_IZVRSILACA BROJ_IZVRSILACA, 
        OPREMLJENOSTI.OPREMLJENOST_ID OPREMLJENOST_ID, 
        OPREMLJENOSTI.PULT PULT, 
        OPREMLJENOSTI.REKLAMA REKLAMA, 
        OPREMLJENOSTI.MOKRI_CVOR MOKRI_CVOR, 
        OPREMLJENOSTI.WC_ZA_IGRACE WC_ZA_IGRACE, 
        OPREMLJENOSTI.WC_ZA_OSOBLJE WC_ZA_OSOBLJE, 
        OPREMLJENOSTI.VENTILATOR VENTILATOR, 
        OPREMLJENOSTI.OSVJETLJENJE OSVJETLJENJE, 
        OPREMLJENOSTI.VRSTA_BROJILA VRSTA_BROJILA, 
        OPREMLJENOSTI.ELEKTRO_INSTALACIJE ELEKTRO_INSTALACIJE, 
        OPREMLJENOSTI.VODO_INSTALACIJE VODO_INSTALACIJE, 
        OPREMLJENOSTI.TELEFONSKE_INSTALACIJE TELEFONSKE_INSTALACIJE, 
        OPREMLJENOSTI.GRIJANJE_ID GRIJANJE_ID, 
        OPREMLJENOSTI.POD_ID POD_ID, 
        OPREMLJENOSTI.PROZORI_VRATA_ID PROZORI_VRATA_ID, 
        OPREMLJENOSTI.OBJEKAT_ID OBJEKAT_ID1, 
        TEHNICKE_OPREMLJENOSTI.TEH_OPR_ID TEH_OPR_ID, 
        TEHNICKE_OPREMLJENOSTI.ONLINE_KLADIONICA ONLINE_KLADIONICA, 
        TEHNICKE_OPREMLJENOSTI.PANO PANO, 
        TEHNICKE_OPREMLJENOSTI.NOSACI NOSACI, 
        TEHNICKE_OPREMLJENOSTI.TV_LCD TV_LCD, 
        TEHNICKE_OPREMLJENOSTI.TV_TELETEXT TV_TELETEXT, 
        TEHNICKE_OPREMLJENOSTI.APARATI_IGRE APARATI_IGRE, 
        TEHNICKE_OPREMLJENOSTI.EVONA EVONA, 
        TEHNICKE_OPREMLJENOSTI.NOVOMATIC NOVOMATIC, 
        TEHNICKE_OPREMLJENOSTI.RULET RULET, 
        TEHNICKE_OPREMLJENOSTI.BILIJAR BILIJAR, 
        TEHNICKE_OPREMLJENOSTI.KLIMA KLIMA, 
        TEHNICKE_OPREMLJENOSTI.OBJEKAT_ID OBJEKAT_ID2, 
        PONUDE.PONUDA_ID PONUDA_ID, 
        PONUDE.ONLINE_TERMINAL ONLINE_TERMINAL, 
        PONUDE.SRECKE SRECKE, 
        PONUDE.ONLINE_KLADIONICA ONLINE_KLADIONICA1, 
        PONUDE.APARATI_IGRE APARATI_IGRE1, 
        PONUDE.RULET RULET1, 
        PONUDE.BILIJAR BILIJAR1, 
        PONUDE.OBJEKAT_ID OBJEKAT_ID3 
    FROM 
        OBJEKTI, 
        OPREMLJENOSTI, 
        TEHNICKE_OPREMLJENOSTI, 
        PONUDE 
    WHERE 
    (PONUDE.OBJEKAT_ID=OBJEKTI.OBJEKAT_ID AND TEHNICKE_OPREMLJENOSTI.OBJEKAT_ID=OPREMLJENOSTI.OBJEKAT_ID) OR (OPREMLJENOSTI.OBJEKAT_ID=OBJEKTI.OBJEKAT_ID AND TEHNICKE_OPREMLJENOSTI.OBJEKAT_ID=OPREMLJENOSTI.OBJEKAT_ID)
     ORDER BY OBJEKTI.OBJEKAT_ID
    The problem I have is any WHERE clause I use I have double values that makes no sense. I checked in the tables and I not all double values. Each Opremljenost has 1 objekat (there are 2 rows of each with its own Objekat) and this applies to 2 other tables (PONUDE and TEHNICKE OPREMLJENOSTI), but for some reason any that they double values. If I run it without a where clause at all clause, I get a repetition of values itself up to 4 times. Does anyone have an idea what's wrong with my request?

    Well, if all relationships are to 1-1 (1-0), then try this (the names of table/column, but you get what I mean bad):

    select OBJ.*, OPR.*, TEH.*, PON.* -- I know you can't do this, but you get what I mean.
    from OBJ,OPR,TEH,PON
    where OBJ.object = OPR.object (+)
      and OBJ.object = TEH.object (+)
      and OBJ.object = PON.object (+)
    /
    

    its supposed to be a 1 to 1 relationship, but it is not.

    In this case the remedy is very simple: create a UNIQUE constraint on the column of the OBJECT in OPR, TEH and PON...

  • I have a problem with a CS6 dynamic table creation

    I have 2 tables, 1 of them is caled 'user', the other a "cars" they are inked with a foreign key in the table of cars there is a column called UserID and takes the value of "user", so my question is I tried to make it dynamic table when the user is connected to display its cars that have his Userid on them only unfortunetly when I do this I get a blank table with nothing in it anyone can help me solve this problem. This is the code I use:

    <? php require_once('Connections/MyConnection.php');? >

    <? PHP

    initialize the session

    If (! isset {})

    session_start();

    }

    * Log out the current user. **

    $logoutAction = $_SERVER ['PHP_SELF']. » ? doLogout = true;

    If ((isset & & ($_SERVER ['QUERY_STRING']! = "")) {})

    $logoutAction. = '& '. htmlentities($_SERVER['QUERY_STRING']);

    }

    {If ((isset($_GET['doLogout'])) & & ($ {_GET ['doLogout'] == "true"))}

    to completely disconnect a visitor, you must delete the session varialbles

    $_SESSION ['MM_Username'] = NULL;

    $_SESSION ['MM_UserGroup'] = NULL;

    $_SESSION ['PrevUrl'] = NULL;

    unset($_SESSION['MM_Username']);

    unset($_SESSION['MM_UserGroup']);

    unset($_SESSION['PrevUrl']);

    $logoutGoTo = "/ cars/LogOut.php";

    If {($logoutGoTo)

    Header ("Location: $logoutGoTo");

    "exit";

    }

    }

    ? >

    <? PHP

    If (! isset {})

    session_start();

    }

    $MM_authorizedUsers = '1', 2;

    $MM_donotCheckaccess = "false";

    Restrict access to Page: grant or deny access to this page

    Function isAuthorized ($strUsers, $UserGroup, $strGroups, $UserName) {}

    For safety, first assuming that the visitor is NOT allowed.

    $isValid = false;

    When a visitor is connected to this site, the MM_Username of Session variable value equal to their username.

    So, we know that a user is NOT logged if this Session variable is empty.

    If (! empty ($UserName)) {}

    In addition to being connected, you can restrict access to only certain users based on a created ID when they connect.

    Analyze the channels in the tables.

    $arrUsers = explode (",", $strUsers);

    $arrGroups = explode (",", $strGroups);

    If (in_array ($UserName, $arrUsers)) {}

    $isValid = true;

    }

    Or, you can restrict access to only certain users based on their user name.

    If (in_array ($UserGroup, $arrGroups)) {}

    $isValid = true;

    }

    If (($strUsers == "") & & false) {}

    $isValid = true;

    }

    }

    return $isValid;

    }

    $MM_restrictGoTo = "/ cars/Home.php";

    If (!) {(((isset($_SESSION['MM_Username']))) & & (isAuthorized ("", $MM_authorizedUsers, $_SESSION ['MM_Username'], {$_SESSION ['MM_UserGroup']})))}

    $MM_qsChar = ';?

    $MM_referrer = $_SERVER ['PHP_SELF'];

    If (strpos ($MM_restrictGoTo, "?")) $MM_qsChar = "&";

    If (isset($_SERVER['QUERY_STRING']) & & strlen($_SERVER['QUERY_STRING']) > 0)

    $MM_referrer. = « ? ». $_SERVER ['QUERY_STRING'];

    $MM_restrictGoTo = $MM_restrictGoTo. $MM_qsChar. "accesscheck =". UrlEncode ($MM_referrer);

    Header ("Location:".) $MM_restrictGoTo);

    "exit";

    }

    ? >

    <? PHP

    If (! function_exists ("GetSQLValueString")) {}

    function GetSQLValueString ($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")

    {

    If (via PHP_VERSION < 6) {}

    $theValue = get_magic_quotes_gpc()? stripslashes ($TheValue): $theValue;

    }

    $theValue = function_exists ("mysql_real_escape_string")? mysql_real_escape_string ($TheValue): mysql_escape_string ($theValue);

    Switch ($theType) {}

    case 'text ':

    $theValue = ($theValue! = "")? « " ». $theValue. "" "": "NULL";

    break;

    case "long":

    case "int":

    $theValue = ($theValue! = "")? intval ($TheValue): 'NULL ';

    break;

    case "double":

    $theValue = ($theValue! = "")? doubleVal ($TheValue): 'NULL ';

    break;

    case "date":

    $theValue = ($theValue! = "")? « " ». $theValue. "" "": "NULL";

    break;

    case "set":

    $theValue = ($theValue! = "")? $theDefinedValue: $theNotDefinedValue;

    break;

    }

    Return $theValue;

    }

    }

    If (! function_exists ("GetSQLValueString")) {}

    function GetSQLValueString ($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")

    {

    If (via PHP_VERSION < 6) {}

    $theValue = get_magic_quotes_gpc()? stripslashes ($TheValue): $theValue;

    }

    $theValue = function_exists ("mysql_real_escape_string")? mysql_real_escape_string ($TheValue): mysql_escape_string ($theValue);

    Switch ($theType) {}

    case 'text ':

    $theValue = ($theValue! = "")? « " ». $theValue. "" "": "NULL";

    break;

    case "long":

    case "int":

    $theValue = ($theValue! = "")? intval ($TheValue): 'NULL ';

    break;

    case "double":

    $theValue = ($theValue! = "")? doubleVal ($TheValue): 'NULL ';

    break;

    case "date":

    $theValue = ($theValue! = "")? « " ». $theValue. "" "": "NULL";

    break;

    case "set":

    $theValue = ($theValue! = "")? $theDefinedValue: $theNotDefinedValue;

    break;

    }

    Return $theValue;

    }

    }

    $maxRows_cars = 10;

    $pageNum_cars = 0;

    If (isset($_GET['pageNum_cars'])) {}

    $pageNum_cars = $_GET ['pageNum_cars'];

    }

    $startRow_cars = $pageNum_cars * $maxRows_cars;

    $colname_cars = "-1";

    If (isset($_SESSION['MM_Username'])) {}

    $colname_cars = $_SESSION ['MM_Username"];

    }

    @mysql_select_db ($database_MyConnection, $MyConnection);

    $query_cars = sprintf ("" SELECT * FROM cars WHERE UserID = %s ", GetSQLValueString ($colname_cars,"int")");

    $query_limit_cars = sprintf ("%s LIMIT %d, %d", $query_cars, $startRow_cars, $maxRows_cars);

    $cars = mysql_query ($query_limit_cars, $MyConnection) or die (mysql_error ());

    $row_cars = mysql_fetch_assoc ($cars);

    If (isset($_GET['totalRows_cars'])) {}

    $totalRows_cars = $_GET ['totalRows_cars'];

    } else {}

    $all_cars = mysql_query ($query_cars);

    $totalRows_cars = mysql_num_rows ($all_cars);

    }

    $totalPages_cars = ceil($totalRows_cars/$maxRows_cars)-1;

    $colname_user = "-1";

    If (isset($_SESSION['MM_Username'])) {}

    $colname_user = $_SESSION ['MM_Username"];

    }

    @mysql_select_db ($database_MyConnection, $MyConnection);

    $query_user = sprintf ("SELECT * FROM 'user' WHERE Email = %s", GetSQLValueString ($colname_user, "text") ");

    $user = mysql_query ($query_user, $MyConnection) or die (mysql_error ());

    $row_user = mysql_fetch_assoc ($user);

    $totalRows_user = mysql_num_rows ($user);

    $colname_user = "-1";

    If (isset($_SESSION['MM_Username'])) {}

    $colname_user = $_SESSION ['MM_Username"];

    }

    @mysql_select_db ($database_MyConnection, $MyConnection);

    $query_user = sprintf ("SELECT FirstName, LastName FROM 'user' WHERE Email = %s", GetSQLValueString ($colname_user, "text") ");

    $user = mysql_query ($query_user, $MyConnection) or die (mysql_error ());

    $row_user = mysql_fetch_assoc ($user);

    $colname_User = "-1";

    If (isset($_SESSION['MM_Username'])) {}

    $colname_User = $_SESSION ['MM_Username"];

    }

    @mysql_select_db ($database_MyConnection, $MyConnection);

    $query_User = sprintf ("SELECT * FROM 'user' WHERE Email = %s", GetSQLValueString ($colname_User, "text") ");

    $User = mysql_query ($query_User, $MyConnection) or die (mysql_error ());

    $row_User = mysql_fetch_assoc ($User);

    $colname_User = "-1";

    If (isset($_GET['MM_Username'])) {}

    $colname_User = $_GET ['MM_Username"];

    }

    @mysql_select_db ($database_MyConnection, $MyConnection);

    $query_User = sprintf ("SELECT * FROM 'user' WHERE Email = %s", GetSQLValueString ($colname_User, "text") ");

    $User = mysql_query ($query_User, $MyConnection) or die (mysql_error ());

    $row_User = mysql_fetch_assoc ($User);

    $colname_User = "-1";

    If (isset($_SESSION['MM_Username'])) {}

    $colname_User = $_SESSION ['MM_Username"];

    }

    @mysql_select_db ($database_MyConnection, $MyConnection);

    $query_User = sprintf ("SELECT * FROM 'user' WHERE Email = %s", GetSQLValueString ($colname_User, "text") ");

    $User = mysql_query ($query_User, $MyConnection) or die (mysql_error ());

    $row_User = mysql_fetch_assoc ($User);

    $colname_User = "-1";

    If (isset($_SESSION['MM_Username'])) {}

    $colname_User = $_SESSION ['MM_Username"];

    }

    @mysql_select_db ($database_MyConnection, $MyConnection);

    $query_User = sprintf ("SELECT * FROM 'user' WHERE UserID = %s", GetSQLValueString ($colname_User, "int") ");

    $User = mysql_query ($query_User, $MyConnection) or die (mysql_error ());

    $row_User = mysql_fetch_assoc ($User);

    ? >

    < ! DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional / / IN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" > ""

    " < html xmlns =" http://www.w3.org/1999/xhtml ">

    < head >

    < link href = "CSS/Layout.css" rel = "stylesheet" type = "text/css" / > "

    < link href = "CSS/Menu.css" rel = "stylesheet" type = "text/css" / > "

    "< link href="/Cars/CSS/VerticalMenu.css "rel ="stylesheet"type =" text/css"/ >

    < meta http-equiv = "Content-Type" content = text/html"; charset = utf-8 "/ >"

    < title > Untitled Document < /title >

    < / head >

    < body >

    < div id = 'Holder' >

    < div id = "Header" >

    < div id = "HeaderContentRight" >

    < table width = "0" border = "0" align = "right" >

    < b >

    < td > logged in as: <? PHP echo $row_user ["FirstName"];? > <? PHP echo $row_user ['name'];? > < table >

    < td > < a href = "<?" PHP echo $logoutAction? > "> sign out < /a > < table >"

    < /tr >

    < /table >

    < / div >

    < / div >

    < div id = "NavBar" >

    < nav >

    < ul >

    "< li > < a href="/Cars/HomeAccount.php "> home < /a > < /li >

    < /ul >

    < / nav >

    < / div >

    < div id = "Content" >

    < div id = "PageHeading" >

    Welcome < h1 >, <? PHP echo $row_user ["FirstName"];? > <? PHP echo $row_user ['name'];? >! < / h1 >

    < / div >

    < div id = "ContentLeft" >

    Control Panel < h6 > < / h6 >

    < p > < / p >

    < ul id = "MyMainMenu" >

    < li > < a href="/Cars/Account.php" > account < /a > < /li > ".

    < li > < a href="/Cars/UpdateAccount.php" > update account < /a > < /li > ".

    < li > < a href="/Cars/CarManagment.php" > car management < /a > < /li > ".

    < /ul >

    < / div >

    < div id = "ContentRight" >

    < table border = "1" align = "center" >

    < b >

    CarBrand < td > < table >

    CarModel < td > < table >

    YearOfProduction < td > < table >

    < /tr >

    <? PHP {? >}

    < b >

    < td > <? PHP echo $row_cars ["CarBrand'];? > < table >

    < td > <? PHP echo $row_cars ["CarModel'];? > < table >

    < td > <? PHP echo $row_cars ["YearOfProduction"];? > < table >

    < /tr >

    <? PHP} while ($row_cars = mysql_fetch_assoc ($cars));? >

    < /table >

    < / div >

    < / div >

    < div id = "Footer" > < / div >

    < / div >

    < / body >

    < / html >

    <? PHP

    mysql_free_result ($CARS);

    mysql_free_result ($User);

    ? >

    Thank you for your time!

    Nowhere on this page I see that you have found the "UserID" variable that is used to query the database of cars everywhere.

    You must get that table "user" when a successful connection occurred.

    Go to your login page and find the code which queries the database (it will look something like the below, your request will be slightly different)

    $LoginRS__query = sprintf ("SELECT username, password loginUsers WHERE username = %s AND password is %s",

    MAKE SURE YOU add to THE QUERY "UserID" (see below.) This is the column of your 'user' table and the foreign key record unique identifier in your table 'cars')

    $LoginRS__query = sprintf ("SELECT UserID, username, password AND password loginUsers WHERE username = %s is %s",

    Then, find the lines of code below:

    $LoginRS = mysql_query ($LoginRS__query, $MyConnection) or die (mysql_error ());

    $loginFoundUser = mysql_num_rows ($LoginRS);

    Include these two lines of code directly after the above code:

    $row = mysql_fetch_assoc ($LoginRS);

    $UserID = $row ['UserID']

    Can find these lines of code:

    If {($loginFoundUser)

    $loginStrGroup = "";

    Declare two session variables and assign them

    $_SESSION ['MM_Username"] = $loginUsername;

    $_SESSION ["MM_UserGroup"] = $loginStrGroup;

    Add this line of code directly after the above code:

    $_SESSION ['username'] = $UserID;

    Now, go to the login page of success (whatever you call that)

    Find the code at the top of the page below:

    If (! isset {})

    session_start();

    }

    Add the line of code below:

    If (! isset {})

    session_start();

    $userID = $_SESSION ['username'];

    }

    Look for the query:

    @mysql_select_db ($database_MyConnection, $MyConnection);

    $query_cars = sprintf ("" SELECT * FROM cars WHERE UserID = %s ", GetSQLValueString ($colname_cars,"int")");

    $query_limit_cars = sprintf ("%s LIMIT %d, %d", $query_cars, $startRow_cars, $maxRows_cars);

    $cars = mysql_query ($query_limit_cars, $MyConnection) or die (mysql_error ());

    $row_cars = mysql_fetch_assoc ($cars);

    and replace with:

    @mysql_select_db ($database_MyConnection, $MyConnection);

    $query_query_cars = "SELECT * FROM cars WHERE userID ="$userID "";

    $query_cars = mysql_query ($query_query_cars, $MyConnection) or die (mysql_error ());

    $row_query_cars = mysql_fetch_assoc ($query_cars);

    $totalRows_query_cars = mysql_num_rows ($query_cars);

    Now, you can pass the details of the car associated with the user ID in the 'user' table and a foreign key in the table "cars."

    You probably want to use a / while loop to get all the information from the database. With a DW repeat region behavior.

Maybe you are looking for