我的Laravel中有3个联合查询,该查询在SQL中有效,但在Laravel中不起作用。并显示以下错误:
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'union all 代码如下所示。
$android = DB::connection("mysql2")->table('android')
->join('game_players', 'game_players.id', '=', 'android.playerId')
->select("android.playerId", "android.dateAdded", "android.identifier")
...
->where("android.dateAdded", "<>", '');
$ios = DB::connection("mysql2")->table('ios')
->join('game_players', 'game_players.id', '=', 'ios.playerId')
->select("ios.playerId", "ios.dateAdded", "ios.identifier")
...
->unionAll($android);
$steam = DB::connection("mysql2")->table(steam')
->join('game_players', 'game_players.id', '=', 'steam.playerId')
->select("playerId", "dateAdded", "identifier")
...
->unionAll($ios)
->get();我真的不知道是什么导致了这个错误,但可能是因为我在3次中调用了联合?对这个有什么想法吗?
Union在只有两个的情况下是有效的,但是当我添加第三个时,它得到了错误
发布于 2019-04-09 03:42:23
我的错误..这就是答案:
$android = DB::connection("mysql2")->table('android')
->join('game_players', 'game_players.id', '=', 'android.playerId')
->select("android.playerId", "android.dateAdded", "android.identifier")
...
->where("android.dateAdded", "<>", '');
$ios = DB::connection("mysql2")->table('ios')
->join('game_players', 'game_players.id', '=', 'ios.playerId')
->select("ios.playerId", "ios.dateAdded", "ios.identifier")
...
$steam = DB::connection("mysql2")->table(steam')
->join('game_players', 'game_players.id', '=', 'steam.playerId')
->select("playerId", "dateAdded", "identifier")
...
->union($ios)
->union($android);
->get();发布于 2019-04-09 04:13:33
请尝试使用eloquent模型的关系,而不是DB。
https://stackoverflow.com/questions/55580443
复制相似问题