Results 1 to 5 of 5

Thread: Max value

  1. #1
    Join Date
    Feb 2009
    Posts
    8

    Unanswered: Max value

    hi,

    i have problem in getting max age. here is my query and its result

    Select G.Country,V.FirstName,L.Language,V.Age,G.Country from Visitors V,Groups G,Vlangs L where V.VisitorID=L.VisitorID AND G.GroupID=V.GroupID and G.Country<>'Brazil' and L.Language='Spanish'

    COUNTRY FIRSTNAME LANGUAGE AGE
    Japan Peter Spanish 45
    USA Issac Spanish 62
    Japan Francis Spanish 43

    i want to get the max age that is 62 in the above result

    Any help will be appreciated
    thanks

  2. #2
    Join Date
    Aug 2003
    Location
    Where the Surf Meets the Turf @Del Mar, CA
    Posts
    7,776
    Provided Answers: 1
    Code:
    SELECT g.country, 
           v.firstname, 
           l.language, 
           v.age, 
           g.country 
    FROM   visitors v, 
           GROUPS g, 
           vlangs l 
    WHERE  v.visitorid = l.visitorid 
           AND g.groupid = v.groupid 
           AND l.language = 'Spanish' 
           AND g.country != 'Brazil'
    >i want to get the max age that is 62 in the above result
    Then use the MAX() function
    You can lead some folks to knowledge, but you can not make them think.
    The average person thinks he's above average!
    For most folks, they don't know, what they don't know.
    Good judgement comes from experience. Experience comes from bad judgement.

  3. #3
    Join Date
    Nov 2003
    Posts
    2,935
    Provided Answers: 12
    Quote Originally Posted by tikan
    i want to get the max age that is 62 in the above result
    Code:
    SELECT max(v.age)
    FROM 
    FROM Visitors V,
         Groups G,
         Vlangs L
    WHERE V.VisitorID = L.VisitorID
    AND   G.GroupID = V.GroupID
    AND   G.Country <> 'Brazil'
    AND   L.Language = 'Spanish';

  4. #4
    Join Date
    Dec 2003
    Posts
    1,074
    or this, if you're looking for only the MAX(age) across all records

    Code:
    SELECT   g.country,
             v.firstname,
             l.language,
             v.age,
             g.country
      FROM   visitors v, GROUPS g, vlangs l
     WHERE       v.visitorid = l.visitorid
             AND g.groupid = v.groupid
             AND l.language = 'Spanish'
             AND g.country != 'Brazil'
             AND v.age =
                   (SELECT   MAX (v2.age)
                      FROM   Visitors V2, Groups G2, Vlangs L2
                     WHERE       V2.VisitorID = L2.VisitorID
                             AND G2.GroupID = V2.GroupID
                             AND G2.Country <> 'Brazil'
                             AND L2.Language = 'Spanish')

  5. #5
    Join Date
    Feb 2009
    Posts
    8
    Thanks Every one
    Chuks its perfect what i wanted thanks man

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •