Skip to main content
fiti tnt
Participating Frequently
May 8, 2009
Frage

[ SQL/recordset ] Show NAME from other table instead of ID

  • May 8, 2009
  • 1 Antwort
  • 3925 Ansichten

I have one problem.

Some tables have only ID that refer from other table, and, in that table, exist what each numer means. When I create one table do display for example 10 itens of my main table, this table just show the ID instead of the NAME, or, will just who the fist NAME of all rows that that have revefenre on both tables.

So what i need Know is:

How to display NAME instead of ID, from one table that have for each ID, one NAME?

In my case, for example, I have the folowing table name and cel name:

CITY
id_city
nameofcity

1 - Rio de Janeiro

2 - São Paulo

3 - Belo Horizonte

4 - Curitiba


USER
id_user
city

1 - 1 : user 1 from city Rio de Janeiro

2 - 1 : user 2 from city Rio de Janeiro

3 - 2 : user 3 from city Rio de Janeiro ( error, must be São Paulo )

4 - 2 : user 4 from city Rio de Janeiro ( error, must be São Paulo )

5 - 4 : user 5 from city Rio de Janeiro ( error, must be Curitiba )

Really thanks for all that help me with this. Also, some link with tutorial or something useful will be really useful.

Dieses Thema wurde für Antworten geschlossen.

1 Antwort

David_Powers
Inspiring
May 8, 2009

SELECT id_user, nameofcity

FROM user, city

WHERE user.city = city.id_city

fiti tnt
Participating Frequently
May 8, 2009

This code do not work. I tryed someting like it before.

On "test' of dreamweaver, just show one list with results that both tables have in comon ( see image attached at this post, especifci about my case ), and on live site, just show the fist name of NAME list. Do not take only the NAME that must take, and take all and show just the fist and wrong data.

As the result on live site, all repeat cells, with diferent cities show only the fist city that are comon on both tables.

I guess that what I'm trying to do is not something so rare of someone use it

David_Powers
Inspiring
May 8, 2009

No, it's not rare. If it's not working, it suggests that your database setup is wrong.

This is a simple example.

cities

city_idcity
1London
2Paris
3Rome

users

user_id
city_idusername
11David
22Jeanne
33Massimo
41John
53Giovanni

David and John are in London

Jeanne is in Paris

Massimo and Giovanni are in Rome