Click here to Skip to main content
15,917,618 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi, the title is messed up i know :D
i have a table called city , there is two columns, city id and city name
now i have another table called flights with three columns, id, time, and city id
i have an item in city table, id=1, city name= slemani,
and now i open flights table and write id=1, time=bla bla, and city id=1
i want to automatically change the city id to the city name, slemani id is 1, and i write 1 in city id, i want that 1 change to slemani automatically, how to do it?

What I have tried:

i tried to get a text using it's id
Posted
Updated 3-Mar-17 18:02pm

Use a JOIN:
SQL
SELECT f.Id, f.Time, c.CityName FROM Flights f
JOIN City c ON c.ID = f.CityId
 
Share this answer
 
Try this:
SELECT f.id, f.time, c.city_name FROM flights f
JOIN city c ON c.city_id = f.city_id WHERE f.city_id=1
Learn SQL Joins[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900