ozmnow
231
1
Laravel

Select from two tables and join result on a third table

Posted 2 years ago by ozmnow

I wonder if its possible to select two tables and join a third table

I have 3 tables:

upvotes -id (PK) -voteOn (FK) - points to users PK -voteBy (FK) - points to users PK -vote (Int) -voteAdded (Int) - unix timestamp

downvotes -id (PK) -voteOn (FK) - points to users PK -voteBy (FK) - points to users PK -vote (tinyInteger) -voteAdded (Int) - unix timestamp

users id (PK) username

What I now want to do is ~ select ALL votes from the tables upvotes and downvotes where voteOn = 2 then join table users on voteBy orderBy voteAdded Asc

More or less I want to get all votes on a specific user then join the users table so that I can get the username of the person who placed the vote

Please sign in or create an account to participate in this conversation.