1. Get rid of all advertisements and get unlimited access to documents by upgrading to Premium Membership. Upgrade to Premium Now and also get a Premium Badge!

from not on place???

Discussion in 'SQL PL/SQL' started by monkey, Jun 6, 2014.

  1. monkey

    monkey Long Term Member

    Messages:
    156
    Likes Received:
    0
    Trophy Points:
    230
    Hello!
    Code (SQL):
    /*create table t1(
    tid int,
    tage int
    );

    insert into t1 values(1,10);
    insert into t1 values(1,20);
    insert into t1 values(1,50);
    insert into t1 values(1,30);*/


    SELECT tid, tage FROM t1
    WHERE tage=(SELECT MAX(tage));
    Please, it says that FROM is not where expected!
    can anyone help?

    Code (SQL):

    /*create table t1(
    tid int,
    tage int
    );

    insert into t1 values(1,10);
    insert into t1 values(1,20);
    insert into t1 values(1,50);
    insert into t1 values(1,30);*/


    SELECT tid, tage FROM t1
    WHERE tage= MAX(tage);
    Here it says there is no group function?
    Does the group function HAVE TO BE=?
    many thanks!!!
     
  2. monkey

    monkey Long Term Member

    Messages:
    156
    Likes Received:
    0
    Trophy Points:
    230
    This works, but it is not the point:
    Code (SQL):
    SELECT MAX(tage) FROM t1;
     
  3. rajenb

    rajenb Forum Expert

    Messages:
    361
    Likes Received:
    114
    Trophy Points:
    655
    Location:
    Mauritius
    You were very close to the solution:

    Code (SQL):
    SELECT tid, tage FROM t1
    WHERE tage=(SELECT MAX(tage) FROM t1);
     
    monkey likes this.
  4. monkey

    monkey Long Term Member

    Messages:
    156
    Likes Received:
    0
    Trophy Points:
    230
    Hello!
    MANY THANKS!!!
    Please, why is THAT not correct (well, I KNOW it is NOT correct, but my q is just WHY is it not correct-hope I am not too annoying!)
    Code (SQL):
    Code SQL:

    /*create table t1(
    tid int,
    tage int
    );
     
    insert into t1 values(1,10);
    insert into t1 values(1,20);
    insert into t1 values(1,50);
    insert into t1 values(1,30);*/

     
    SELECT tid, tage FROM t1
    WHERE tage= MAX(tage);

     
     
  5. rajenb

    rajenb Forum Expert

    Messages:
    361
    Likes Received:
    114
    Trophy Points:
    655
    Location:
    Mauritius
    You cannot use the MAX function (or any aggregate function) directly in a WHERE clause.
     
    monkey likes this.