gpt4 book ai didi

mysql - laravel 如何在 DB Query 中管理多个联合

转载 作者:行者123 更新时间:2023-11-30 21:32:17 26 4
gpt4 key购买 nike

我的 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?对这个有什么想法吗?

如果它只有两个,联合就可以工作,但是当我添加第三个时,它得到了错误

最佳答案

我的错误..这是答案:

$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();

关于mysql - laravel 如何在 DB Query 中管理多个联合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55580443/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com