Results 1 to 3 of 3

Thread: SQL help!!

  1. #1
    Join Date
    Oct 2002
    Posts
    29

    Question Unanswered: SQL help!!

    I have a table (acctTran) as follows

    Acct Tra. Type TranDate
    1 D 8/1/02
    1 W 8/3/02
    1 W 8/7/02
    2 W 8/4/02
    2 D 8/8/02
    2 W 8/9/02
    3 W 8/2/02
    3 W 8/5/02
    3 D 8/6/02

    I want to write a query to extract first tranaction date for each account
    the following query works fine

    select acct, min(transDate) from acctTran
    group by acct

    This results,
    1, 8/1/02
    2, 8/4/02
    3,8/2/02

    Now my question is, How to write a query to get the following result?

    1, 8/1/02, D
    2, 8/4/02, W
    3,8/2/02, W

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    correlated subselect

    select acct, transDate, TranType
    from acctTran
    where transDate =
    ( select min(transDate)
    from acctTran
    where acct = xxx.acct )

    rudy
    http://rudy.ca/

  3. #3
    Join Date
    Oct 2002
    Posts
    29
    Thanks.

Posting Permissions

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