Sql examination questions, how to write, ask for advice!

is like this, and the ultimate effect is to match the avatar address of the drink in the user table for each comment list

first, query out the table_1 (article comment table) article comment result set

then I found that these comments do not have user avatars, so I need to associate the table_2 (user table) of the query. In this place, the reply_user in the result set of the first comment query is associated with the username in the table_2 (user table).

the user avatar to be queried is in the avatar_link field of table_2 (user table)

then merge the list of comments and the corresponding avatar (each comment corresponds to a different user avatar)

solve the problem, sql is not good at learning

Mar.13,2021

--sql

SELECT a.*,b.avatar_link

FROM [dozhan_reply] a

INNER JOIN [dozhan_user] b ON a.reply_user = b.username

WHERE a.reply=69

related queries can't you? In addition, it is best to use the text to describe the problem. It looks convenient for


to describe the problem vaguely. The avatar address should be returned in the picture, and the text expression should be returned as well.
if the former, go to the top floor, make an association query, and then return avatar_link. For details, see https://bbs.csdn.net/topics/3.


is the most basic join query. Refer to SQL's four join queries

Note that the article is SQL Server syntax. You can find out how to write the syntax of MySQL .

Menu