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 8314279
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T20:45:49+00:00 2026-06-08T20:45:49+00:00

I am new to MySql and sql. i can’t figure out how to do

  • 0

I am new to MySql and sql.
i can’t figure out how to do the following:

i have a bus schedule database with four relevant tables:

stops (24,403 rows)
-------------------
stop_id   int(11)


stopTimes (12,073,459 rows)
---------------------------
trip_id         varchar(30)
stop_sequence   int(11)     // running sequence within the trip: 1-last
stop_id         int(11)

trips (320,395 rows) 
---------------------------
trip_id   varchar(30)
route_id  int(11)


routes (9,748 rows)
---------------------------
route_id            int(11)
agency_id           int(11)                     
route_short_name    varchar(10)

relations

  • routes to trips: one to many
  • trips to stopTimes: one to many
  • stops to stopTimes: one to one

out of these tables i would like to create a new table “routeStops” with the following fields:

routeStops (~100,000 rows)
---------------------------
route_id            int(11)
agency_id           int(11)                     
route_short_name    varchar(10)
stop_id   int(11)

with a one to many relationship between it and the stops.

is there an SQL query that can perform that?

should i add an index to the route_id and stop_id to optimize performance? should i add a fulltext index to trip_id?

i am new to that and will appreciate some insights.

i am using PHPMyAdmin and a rather new XAMPP installation.

tnx,

  • 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-06-08T20:45:50+00:00Added an answer on June 8, 2026 at 8:45 pm

    Is there an SQL query that can perform that?

    You can achieve it using the INSERT … SELECT syntax:

    INSERT INTO routeStops (route_id, agency_id, route_short_name, stop_id)
    SELECT DISTINCT r.route_id, r.agency_id, r.route_short_name, s.stop_id
      FROM routes r
      JOIN trips t ON r.route_id = t.route_id
      JOIN stopTimes s ON t.trip_id = s.trip_id;
    

    Should I add an index to the route_id and stop_id to optimize performance?

    Those should be the primary key in their tables, and a foreign key in the other tables.

    Should I add a fulltext index to trip_id?

    I don’t recommend it because it would be too slow. I suggest that you alter your tables and use an int for the trip_id:

    CREATE TABLE trips (
      trip_id int(10) unsigned NOT NULL,
      trip_id_old varchar(30) DEFAULT NULL,
      route_id int(11) DEFAULT NULL,
      PRIMARY KEY (trip_id)
    )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can we create a new MySQL database( not a table, I want a new
I have a MySQL database and every 6 months, a new table is created
I have a number of tables I need to convert from mySQL to SQL
Disclaimer: I am completely new to PHP and MySQL/SQL. I have multiple implode() functions
I am new to mysql and I have been pulling my hair out about
Alright, so I'm fairly new to PHP and SQL/MySQL so any help is appreciated.
I created a new mysql database and i want to use foreign keys with
I'm migrating an old Sybase database to a new MySQL db. Since the moment
I am new to MySQL, but I have used Oracle for some time. I
In my MySQL InnoDB database, I have dirty zip code data that I want

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.