Reputation: 41
I saw numbers of answers for this questions but all answers seem to point to the same result. I need to inner join 2 tables with one column that has the same name in both. My code:
$sql="SELECT * FROM Bets
INNER JOIN Users ON Bets.UserID = Users.UserID
INNER JOIN Games ON Bets.GameID = Games.GameNo
WHERE GameID = '$NGnumber' ORDER BY DrawOrder";
In all posts i've seen, the solution is to create an alias on the column that has the same name, for instance:
$sql="SELECT Bets.AwayScore AS B-away FROM Bets
INNER JOIN Users ON Bets.UserID = Users.UserID
INNER JOIN Games ON Bets.GameID = Games.GameNo
WHERE GameID = '$NGnumber' ORDER BY DrawOrder";
But I have a lot of columns to select, if I write them all my SQL query will take forever to write! Is there a way to create an alias while keeping SELECT * from Bets
?
Thanks!
Upvotes: 0
Views: 174
Reputation: 204746
If you want to select all columns of a table then use tablename.*
SELECT b.*, b.AwayScore as bet_awayscore, g.AwayScore as game_awayscore
FROM Bets b
INNER JOIN Users u ON b.UserID = u.UserID
INNER JOIN Games g ON b.GameID = g.GameNo
WHERE b.GameID = '$NGnumber'
ORDER BY DrawOrder
Upvotes: 2