I can't inner join with a table twice
I have these two tables:
I need to inner join the two tables twice to get the owner and the author in one request.
the query I write is:
and I get this error:
sqlMessage: "Not unique table/alias: 'users'"
Is there a way to do it without having to query two times?
I suspect that the error is because the users table would output duplicate columns but how do I rename those columns for each inner join?4 Replies
Why are you joining the same table twice?
Did you mean to join the
users
table based on two conditions? If that's the case, then you could do something like this:
This will return the articles by the user, no matter if he's the author or the owner of itno I want to get the name of the owner and the name of the author. that's why I need to do this.
yes but I need to get both
It would have been easier if I just hard coded the names in the articles table but If the usernames got changed the constraint would need to cascade etc...
Try something like this:
I'm not sure if it's gonna work, I wrote it from top of my head, but try to get the idea.
kinda...
it only needed the two(same) tables to have unique tables alias and column aliases.
it worked however this way:
thanks tho @circles