- Aug 12, 2001
- 1,762
- 0
- 0
I have a table that contains two integer values which represent a "to" userid, and a "from" userid.
I have another table that contains an integer value (primary key) plus a username string.
Example:
MESSAGES TABLE
to_userid from_userid
1 2
2 3
5 14
USER TABLE
userid username
1 John
2 Lacey
3 Evelyn
I want to make a query that will display all rows of the messages table, converting both columns to the usernames.
Here's what I came up with that converts just one column:
select user.username, messages.from_userid from messages, user where user.userid = messages.to_userid;
I know that this is a hack and it logically does not fully make sense. Someone, please give me the right query!
I have another table that contains an integer value (primary key) plus a username string.
Example:
MESSAGES TABLE
to_userid from_userid
1 2
2 3
5 14
USER TABLE
userid username
1 John
2 Lacey
3 Evelyn
I want to make a query that will display all rows of the messages table, converting both columns to the usernames.
Here's what I came up with that converts just one column:
select user.username, messages.from_userid from messages, user where user.userid = messages.to_userid;
I know that this is a hack and it logically does not fully make sense. Someone, please give me the right query!
