Max VS Inner Join Problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • haryu
    New Member
    • Jan 2007
    • 3

    #1

    Max VS Inner Join Problem

    Max VS Inner Join Problem....this script will show all row in table X2. How to Break it ?

    =============== =====
    Id Name
    =============== =====
    1 a
    2 b
    3 c

    Table X2
    =============== =============== =============== ============
    Id IdX1 Price Description
    1 1 100 AA
    2 1 200 BB
    3 2 300 CC
    4 2 400 DD

    i want result Be :

    Name Max_Price Description
    =============== =============== =============== ======
    a 200 BB
    b 400 DD


    BEFORE i use :
    select x1.name, max(x2.Max_Pric e) as maxprice, x2.description from x1 INNER JOIN x2 on x1.id=x2.idX1 group by name,descriptio n order by Name ASC; but this script will show all row in table X2. How to Break it ?
  • ronverdonk
    Recognized Expert Specialist
    • Jul 2006
    • 4259

    #2
    Of course it does. Tell (in words) what you want to accomplish with your query.

    Ronald :cool:

    Comment

    • bartonc
      Recognized Expert Expert
      • Sep 2006
      • 6478

      #3
      Originally posted by haryu
      Max VS Inner Join Problem....this script will show all row in table X2. How to Break it ?

      =============== =====
      Id Name
      =============== =====
      1 a
      2 b
      3 c

      Table X2
      =============== =============== =============== ============
      Id IdX1 Price Description
      1 1 100 AA
      2 1 200 BB
      3 2 300 CC
      4 2 400 DD

      i want result Be :

      Name Max_Price Description
      =============== =============== =============== ======
      a 200 BB
      b 400 DD


      BEFORE i use :
      select x1.name, max(x2.Max_Pric e) as maxprice, x2.description from x1 INNER JOIN x2 on x1.id=x2.idX1 group by name,descriptio n order by Name ASC; but this script will show all row in table X2. How to Break it ?
      You may be thinking of:
      select x1.name, max(x2.Max_Pric e) as maxprice, x2.description from x1 INNER JOIN x2 WHERE x1.id=x2.idX1 group by name,descriptio n order by Name ASC;
      which should not give the cartesian product as before.

      Comment

      • haryu
        New Member
        • Jan 2007
        • 3

        #4
        if just using :

        select ....from X1,X2 Where.......Gro up By.

        all row in table X2 will be show.....

        I want Max Row in Table X2 base on X1. See My Example.

        Comment

        • haryu
          New Member
          • Jan 2007
          • 3

          #5
          SELECT x1.name,x2.maxp rice,x2.descrip tion FROM x1 join x2 on x1.pkid=x2.fkid where x2.maxprice in(select max(maxprice) from x2 where x1.pkid=x2.fkid ); --> Answer by Re_Boot from Vb channel in dalnet, thanks alot bro.

          Comment

          Working...