I want to query the user table through the username to get the user ID, query the comment table through the user ID to get all the comments of this user, query the topic table through the tid field in the comment, and get the post where the comment is located, and pass the post's uid gets the author of this post.
Here comes the problem. I start the query from the user table, and join the comment table and topic table respectively. Then when I check the post author through the post uid, I need to check the username from the user table again. This time the username refers to is the username of the author who published the post, not the username passed in at the beginning.
mysql keeps prompting me Column 'username' in where clause is ambiguous
Why...
I want to query the user table through the username to get the user ID, query the comment table through the user ID to get all the comments of this user, query the topic table through the tid field in the comment, and get the post where the comment is located, and pass the post's uid gets the author of this post.
Here comes the problem. I start the query from the user table, and join the comment table and topic table respectively. Then when I check the post author through the post uid, I need to check the username from the user table again. This time the username refers to is the username of the author who published the post, not the username passed in at the beginning.
mysql keeps prompting me Column 'username' in where clause is ambiguous
Why...
When querying fields when connecting tables, you must clearly indicate which table they belong to, such as
SELECT(a.username,a.id,b.,c.) FROM user AS a
LEFTJOIN comment AS b ON a.id = b.uid
LEFTJOIN topic AS c ON b.tid = c.id
Can you post the sql? Because you have queried the user table twice. If it is a sql, you have to define aliases for the two user tables respectively. Otherwise, if you use username directly in where, it will report Column ' username' in where clause is ambiguous error. Please use alias.username in the where condition
1 2 |
|