我有两个表和两个连接(mysql)用于一个表-dbname\u web(mysqlshop)用于第二个表-dbname\u shop
这三个查询都可以正常工作,但当我使用union时,第一个连接丢失,只显示来自mysqlshop的第二个连接
laravel错误是dbname\u shop.news不存在它必须是dbname\u 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%))
暂无答案!
目前还没有任何答案,快来回答吧!