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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T13:58:05+00:00 2026-05-27T13:58:05+00:00

I Created a table like this for indian railways project: CREATE TABLE IF NOT

  • 0

I Created a table like this for indian railways project:

CREATE TABLE IF NOT EXISTS `dennis` (
  `trid` varchar(50) NOT NULL,
  `place` varchar(50) NOT NULL,
  `si` varchar(50) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

then i inserted rows this way :

INSERT INTO `dennis` (`trid`, `place`, `si`) VALUES
('100', 'cochi', '3'),
('300', 'cochi', '1'),
('100', 'mumbai', '1'),
('100', 'bangalore', '2'),
('300', 'bangalore', '2'),
('300', 'mumbai', '3'),
('200', 'hyderabad', '1'),
('400', 'trivandrum', '1'),
('200', 'bangalore', '2'),
('200', 'trivandrum', '3'),
('400', 'bangalore', '2'),
('400', 'hyderabad', '3');

My problem is when i select start station as Bangalore and destination as mumbai, I am getting all the train numbers because bangalore exist for all trid ie trainid but mumbai exist only for 100 and 300.

I need a query that can return only those trid who have both mumbai and bangalore. Also the si ie Serialnumber of bangalore must be lesser than si of mumbai.

i used this query but it seems to return all the record

SELECT DISTINCT trid FROM dennis WHERE place ='mumbai' OR place='bangalore'
  • 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-27T13:58:06+00:00Added an answer on May 27, 2026 at 1:58 pm

    try this,

    SELECT DISTINCT d1.trid 
    FROM dennis d1
         INNER JOIN dennis d2 ON d2.trid=d1.trid
    WHERE d1.place = 'bangalore' and d2.place = 'mumbai' AND d1.si < d2.si
    

    hope this answers your question

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

Sidebar

Related Questions

I have created a table like this: CREATE TABLE #TEMP(RecordDate datetime, First VARCHAR(255), Last
I have a table like this: CREATE TABLE IF NOT EXISTS `session` ( `id`
Say I have a table like so: CREATE TABLE big_table (UUID varchar(32) not null,
I have created an index on my table like this: CREATE INDEX index_typ_poplatky ON
I have a table that's created like this: CREATE TABLE bin_test (id INTEGER PRIMARY
Given a table structure like this: CREATE TABLE `user` ( `id` int(10) unsigned NOT
If my table looks like this: CREATE TABLE `daily_individual_tracking` ( `daily_individual_tracking_id` int(10) unsigned NOT
In MSSQL I have a table created like this: CREATE TABLE [mytable] (fkid int
I have a table created using Python + Sqlite3 c.execute('CREATE TABLE IF NOT EXISTS
I created db-table like this, # ./zf.sh create db-table TestModel admin and now I

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.