我看到了这些问题的答案数量,但所有答案似乎都指向相同的结果。 我需要内部连接2个表,其中一列具有相同的名称。我的代码:
$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";
在我看到的所有帖子中,解决方案是在具有相同名称的列上创建别名,例如:
$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";
但我有很多列要选择,如果我写它们我的所有SQL查询将永远写入!有没有办法在保留SELECT * from Bets
时创建别名?
谢谢!
答案 0 :(得分:2)
如果要选择表格的所有列,请使用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