I want to query the user table by username to obtain the user ID, query the comment table by user ID to obtain all comments from this user, query the topic table by the tid field in the comment, and obtain the post where the comment is located, obtain the author of the post by using the Post uid. The problem is that I am from the user table... I want to query the user table by username to obtain the user ID, query the comment table by user ID to obtain all comments from this user, query the topic table by the tid field in the comment, and obtain the post where the comment is located, obtain the author of the post by using the Post uid.
The problem is that I started to query the user table and joined the comment table and topic table respectively. when I checked the post author through the post uid, you also need to check the username from the user table. this time username refers to the username of the author who posted the post, not the username passed in at the beginning.
Mysql always prompts me Column 'username' in where clause is ambiguous
Why...
Reply content:
I want to query the user table by username to obtain the user ID, query the comment table by user ID to obtain all comments from this user, query the topic table by the tid field in the comment, and obtain the post where the comment is located, obtain the author of the post by using the Post uid.
The problem is that I started to query the user table and joined the comment table and topic table respectively. when I checked the post author through the post uid, you also need to check the username from the user table. this time username refers to the username of the author who posted the post, not the username passed in at the beginning.
Mysql always prompts me Column 'username' in where clause is ambiguous
Why...
When a table is connected, the query field must clearly specify the table field, for example
SELECT (a. username, a. id, B., C.) FROM user AS
LEFTJOIN comment AS B ON a. id = B. uid
LEFTJOIN topic AS c ON B. tid = c. id
Can I post the SQL statement? because you have queried the user table twice. if it is an SQL statement, you need to define an alias for the two user tables respectively, otherwise, the Column 'username' in where clause is ambiguous error will be reported if you directly use username in where. use the alias in the where condition. username method
For the select table as, the name is similar to: select * from tmp as t1 left join tmp as t2 on t1.uid = t2.uid