MySQL a statement associates two fields of another table at the same time

now I have encountered a statement that cannot be written when designing a mysql article comment section that encounters a MySQL statement. Look at the table first:

the last result I want is: Zhang San replied to Li Si: the article is very good
according to my experience, using MySQL"s where method can only get the name of uid or to_uid in user in comment table, for example:

select * from user u, comment c where u.uid = c.uid

what comes out of the above sentence is the name value of the commentator (Zhang San) in the comment table, and the name value of Li Si can not be reached. Is there any way to get the name value of Zhang San and Li Si at the same time? thank you for your advice!

Mar.31,2021

 

select
(select name from user where user.uid = c.uid) as replyer,
(select name from user where user.uid = c.to_uid) as replyed,
c.content
from comment c
where id=1

it is understood that the data is in the comment table, but comment.uid and comment.to_uid need to be escaped into names.
the above sql may provide some solutions.

Menu