This is driving me nuts.
So, I did a simple query to link two tables together to do such things as make a user id into a username for display.
That is a simple working example. It simply displays usernames for every "from userid" and it does this by matching to the userid in the users table. Simple, works, I'm happy.
Now, I cannot figure out how to do the more complicated one.
See, the problem is I need to make two identical selects almost...
I'm missing something because that is gibberish in SQL speak.
How do I solve this problem in one SQL line? I know this has to be solvable because it makes no sense to not be able to do it... but I have no idea how to do it.
Help?
So, I did a simple query to link two tables together to do such things as make a user id into a username for display.
Code:
SELECT
`u`.`username`
FROM `users_table` AS `u`, `messages_table` AS `pm`
WHERE
`pm`.`messages_from_userid` = `u`.`user_id`;
That is a simple working example. It simply displays usernames for every "from userid" and it does this by matching to the userid in the users table. Simple, works, I'm happy.
Now, I cannot figure out how to do the more complicated one.
Code:
SELECT
`u`.`username` as `usernameF`, `u`.`username` as `usernameT`
FROM `messages_table` AS `pm`, `users_table` AS `u`
WHERE
... um ... I dunno ...
Code:
WHERE
`pm`.`messages_from_userid` = `u`.`user_id`;
Store above result in usernameF
Also do the following... and store that result in usernameT
WHERE
`pm`.`messages_to_userid` = `u`.`user_id`;
I'm missing something because that is gibberish in SQL speak.
How do I solve this problem in one SQL line? I know this has to be solvable because it makes no sense to not be able to do it... but I have no idea how to do it.
Help?