Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 235695
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T20:17:09+00:00 2026-05-11T20:17:09+00:00

Its been a while since my Database Design classes in my sophomore year at

  • 0

Its been a while since my Database Design classes in my sophomore year at Uni. and I haven’t done any designs in the interim so my skills are at best rusty at the moment. I have begun working on a personal project involving the railway timetable system and seem to be stuck at the table design which resembles something like this –

StationTbl
------------
  StnName
  StnCity
  StnCode -  {Primary Key}

TrainTbl
---------
  TrnName
  TrnNumber -  {Primary Key}
  SourceStn
  DestStn
  DaysofWeek 

TrainHopTbl
--------------
  TrnNumber   -  {Primary Key}
  StationCode -  {Primary Key}
  ArrTime
  DepTime
  HopIndex

Most fields are alphanumberic with the exception of the Time fields and the HopIndex in TrainHopTbl. As you can see the preliminary design is very crude and far from finished.

Users will be able to find trains based on either the train name/number or by specifying the source and destination station. The first query can be easily dealt with but I am having problems writing a query for the second search where the user gives the src/dest pair and the server returns a list of trains which run on that route. This information will be extracted from TrainHopTbl which contains the list of hops for the particular train, like so –

TrainHopTbl
--------------
Num StnCode  ArrTime  DepTime  HopIndex
121  WDC     0900      0910        1
121  BAL     1005      1010        2
121  NYC     1145       -          3

If the user enters WDC/NYC as the src/dest pair then the query should return Train Number 121 since it is a valid route.

Any pointers/links/book suggestions on database design would be helpful. Heck, at this point even runnable queries or entire re-designs would be helpful since I seem to be stuck in a rut that I am finding hard to get out of and this has completely stalled my progress.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T20:17:09+00:00Added an answer on May 11, 2026 at 8:17 pm

    I’d take your SourceStn and DestStn out of your TrainTbl — it’s needless clutter.

    Anyway, you can get what you’re looking for with:

    select 
        src.TrnNumber,
        srcSt.StnName as SourceStation, 
        srcSt.StnCity as SourceCity,
        src.DepTime,
        destSt.StnName as DestinationStation,
        destSt.StnCity as DestinationCity,
        dest.ArrTime,
        (abs(dest.HopIndex - src.HopIndex)) as Stops
    from
        TrainHopTbl src
        inner join TrainHopTbl dest on
            src.TrnNumber = dest.TrnNumber
        inner join StationTbl srcSt on
            src.StnCode = srcSt.StationCode
        inner join StationTbl destSt on
            dest.StnCode = destSt.StationCode
    where
        src.StnCode = 'WDC'
        and dest.StnCode = 'NYC'
        and src.HopIndex < dest.HopIndex
    order by
        Stops asc,
        DepTime asc
    

    Edit: I haven’t taken into account transfers here. Your question mentioned just straight route trains. Let me know if you want transfers, as well.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

It's been a while since I've had to do any HTML-like code in Vim
So this is a purely academic question, mostly as its been a while since
It's been a while since I've programmed a GUI program, so this may end
It's been a while since I last coded arm assembler and I'm a little
It's been a while since I was in college and knew how to calculate
It's been a while since I used GTK+, and the last time I did
It's been a while since I programmed in C++, and after coming from python,
It's been quite a while since I last used D Programming Language , and
It's been a while now since Microsoft stopped supporting Embedded Visual C++ 4.0 (eVC
I have been developing in asp.net since its existence (also classic asp before that)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.