我有两个表和两个连接 (mysql)适用于一个表 - dbname_web (mysqlShop)适用于第二个表--dbname_shop
所有三个查询工作正常,但当我使用联合 第一个连接丢失,只显示来自mysqlShop的第二个连接
laravel错误是dbname_shop.News不存在 它必须是dbname_web.News
$News = DB::connection('mysql')->table('News')->selectRaw("title_ge as name, CONCAT('$news_url/', id) as url")
->where("title_ge","LIKE","%{$request->input('query')}%")
->orWhere("full_text_ge","LIKE","%{$request->input('query')}%");
$Album = DB::connection('mysql')->table('Album')->selectRaw("title_ge as name, CONCAT('$album_url/', id) as url")
->where("title_ge","LIKE","%{$request->input('query')}%")
->orWhere("full_text_ge","LIKE","%{$request->input('query')}%");
$Products = DB::connection('mysqlShop')->table('Products')->selectRaw("title_ge as name, CONCAT('$product_url/', id) as url")
->where("title_ge","LIKE","%{$request->input('query')}%")
->orWhere("soft_id","LIKE","%{$request->input('query')}%")
->orWhere("full_text_ge","LIKE","%{$request->input('query')}%");
$result = $Products->union($News)->union($Album)->get();
return response()->json($result);
SQL输出
(select title_ge as name, CONCAT('http:\/\/nova.ge\/product\/item\/', id) as url from `Products` where `title_ge` LIKE ? or `soft_id` LIKE ? or `full_text_ge` LIKE ?) union (select title_ge as name, CONCAT('http:\/\/nova.ge\/news\/', id) as url from `News` where `title_ge` LIKE ? or `full_text_ge` LIKE ?) union (select title_ge as name, CONCAT('http:\/\/nova.ge\/album\/', id) as url from `Album` where `title_ge` LIKE ? or `full_text_ge` LIKE ?)
错误
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'novage_shop.News' doesn't exist (SQL: (select title_ge as name, CONCAT('http://nova.ge/product/item/', id) as url from `Products` where `title_ge` LIKE %test search% or `soft_id` LIKE %test search% or `full_text_ge` LIKE %test search%) union (select title_ge as name, CONCAT('http://nova.ge/news/', id) as url from `News` where `title_ge` LIKE %test search% or `full_text_ge` LIKE %test search%) union (select title_ge as name, CONCAT('http://nova.ge/album/', id) as url from `Album` where `title_ge` LIKE %test search% or `full_text_ge` LIKE %test search%))