Need a select...
DBAsupport.com Forums - Powered by vBulletin
Results 1 to 4 of 4

Thread: Need a select...

  1. #1
    Join Date
    May 2001
    Location
    Atlanta US
    Posts
    262
    Hi Gurus,

    Have a table with following data

    Name date
    James 5-MAR-02
    Janes 6-MAR-02
    John 6-MAR-02
    John 8-MAR-02

    I need a select where I get the latest date for a particular user.

    Thanks!
    Hemant

  2. #2
    Join Date
    May 2002
    Posts
    2,645
    select name, max(date) from table_name
    group by name;

    SQL> select * from supp2;

    NAME DATE_IN
    ---------- ---------
    John 16-SEP-02
    John 13-SEP-02
    James 15-SEP-02
    James 14-SEP-02
    James 13-SEP-02

    SQL> select name, max(date_in)
    2 from supp2
    3 group by name;

    NAME MAX(DATE_
    ---------- ---------
    James 15-SEP-02
    John 16-SEP-02

  3. #3
    Join Date
    Sep 2001
    Location
    NJ, USA
    Posts
    1,287
    If u need to get data about all users --> see stecal post.
    If u need only one particular user:

    select max(date_in) from t1 where name = 'John';
    or
    select name, max(date_in) from t1
    group by name
    having name = 'John';

  4. #4
    Join Date
    Nov 2000
    Location
    Baltimore, MD USA
    Posts
    1,339
    Originally posted by Shestakov
    If u need to get data about all users --> see stecal post.
    If u need only one particular user:

    select max(date_in) from t1 where name = 'John';
    or
    select name, max(date_in) from t1
    group by name
    having name = 'John';
    Note that the first statement is far more efficient than the second.

    - Chris
    Christopher R. Long
    ChrisRLong@HotMail.Com
    But that's just my opinion. I could be wrong

Posting Permissions

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



Click Here to Expand Forum to Full Width