0

我看到了这个问题的许多答案,但所有答案似乎都指向相同的结果。我需要将 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

谢谢!

4

1 回答 1

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
于 2013-10-24T18:43:10.063 回答