mysql - Replace field with field from other table in SELECT query -


let have 2 tables follows:

database.users

user_id | username -------------------     1   | some_name     2   | another_name     ... 

database.comments

user_id | comment ------------------     1   | some_comment     2   | another_comment     ... 

how run select gets comments based on user_id , return result user_id replaced username database.users?

here query:

select u.username, c.comment users u join comments c on u.user_id = c.user_id order u.username 

i added "order by" clause, comments 1 user together.

alternatively, can add "where" clause select particular user.


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -