#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2011
    Posts
    11
    Rep Power
    0

    Using MAX function in SQL


    Hi all

    I am new to this forum so thanks for any advice i have read so far in previous posts.

    I am trying to use the MAX function to get one row of information in my output.
    It is hard for me to describe the problem as the tables are new to me.

    Seq 1 will give me the first location but I need to find the maximum seq as it can vary and that will represent the final arrival location and from it the time.


    SELECT
    tr.trainnumber TID,
    tr.secondarynumber T_UID,
    ts.departuretime dep_time,
    ts.arrivaltime arr_time,
    sh.name st_name
    --sh2.name st_name2

    FROM kbase.TRAINRUN tr, kbase.TRAINSTATION ts, kbase.STATIONHEADER sh, kbase.STATIONHEADER sh2

    WHERE tr.id = ts.fahrplanid
    AND tr.schedversionid = 18
    AND tr.secondarynumber LIKE 'R%'
    AND ts.stationid = sh.id
    AND ts.seq = 1
    AND ts.seq = SELECT(MAX(SEQ) FROM kbase.TRAINSTATION ts2 WHERE ts.fahrplanid = ts2.fahrplanid AND ts2.schedversionid = 18)
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Oct 2003
    Location
    Germany
    Posts
    2,803
    Rep Power
    352
    And your question is?

    Comments on this post

    • Vomster agrees
  4. #3
  5. Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2005
    Posts
    724
    Rep Power
    295
    Does that query return anything? From what I see it won't.

IMN logo majestic logo threadwatch logo seochat tools logo