0

I have a trip table with columns from_city and to_city which contain foreign key to city table.

How to join with a city table with id as primary key so that I get a result joined table with from_city_name and to_city_name?

1
  • 1
    Not sure what is the issue. Just join the city table twice using different aliases. Commented Feb 14, 2019 at 3:16

1 Answer 1

1

Do an inner join twice, as illustrated below. For more information on SQL joins see MySQL Join Made Easy For Beginners

SELECT
    B.name from_city_name, C.name to_city_name 
FROM 
    trip A 
INNER JOIN 
    city B
ON A.from_city=B.id 
INNER 
    JOIN city C 
ON A.to_city=C.id;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.