当前位置:网站首页>Db查询数据库合并两个不相关的表,新增不存在的字段,并赋予默认值
Db查询数据库合并两个不相关的表,新增不存在的字段,并赋予默认值
2022-06-29 20:57:00 【向宇it】
需求:两个数据库中有两个不相关的表,我需要将它们合并,并在order2中新增不存在的product_name字段,并赋予默认值
$product_name = '默认值';
$news = DB::table("guild_pay.order1")
->where('status', '=', 1)
->selectRaw('product_name','order_no','money','create_time');
$res = Db::table('guild_pay.order2')
->where('status', '=', 1)
->union($news)
->selectRaw('IFNULL(null, ?) as product_name, order_no, money, create_time', [$product_name])
->orderBy('create_time', 'desc')
->paginate(10)->toArray();
ps:记得两个表的字段要一一对应,不可以一边多一边少,也不可以换位置
边栏推荐
- How can colleges and universities build future oriented smart campus based on cloud native? Full stack cloud native vs traditional technology architecture
- Curl download example
- CORDIC based Signal Processor desgn
- "Operation and maintenance department has Xiao Deng" to review and analyze file and folder access rights
- 注解
- Rsync 的简单应用与配置
- PostgreSQL Weekly News - 22 juin
- 不同系统下的文件层级符号小结
- 每周招聘|DBA数据工程师,年薪35+ ,梦起九州,星河灿烂!
- Information system project manager -- Chapter VII examination questions of project cost management over the years
猜你喜欢

Chainsafe cross chain bridge deployment tutorial

THREEJS基础入门

. NETCORE unified authentication authorization learning - first authorization (2)

Practical guide to GStreamer application development (V)

Mapbox GL development tutorial (12): loading surface layer data

Implementation and Simulation of ads131a04 ADC Verilog

"Xiaodeng" active directory password expiration notification function is available for operation and maintenance

Sentinel's quick start takes you through flow control in three minutes

Detailed description of gaussdb (DWS) complex and diverse resource load management methods

「运维有小邓」实时监控用户登录操作
随机推荐
Chainsafe cross chain bridge deployment tutorial
"Xiaodeng" active directory batch user creation in operation and maintenance
How to evaluate iFLYTEK AI translation pen P20 series? Is it worth buying?
In depth good article | yolov5+deepsort multi-target tracking in-depth interpretation and testing (including source code)
Design of VHDL telephone billing system
Set up your own website (12)
Mysql Json 数据类型&函数
AI scene Storage Optimization: yunzhisheng supercomputing platform storage practice based on juicefs
leetcode:370. 区间加法
PostgreSQL Weekly News - 22 juin
习近平在湖北武汉考察时强调 把科技的命脉牢牢掌握在自己手中 不断提升我国发展独立性自主性安全性
Stm32cubemx learning (6) external interrupt experiment
How to call RFC function of ABAP on premises system directly in SAP BTP ABAP programming environment
Website stress testing tool - webbench
Advances in computational imaging
Common methods of string class
Leading by 11%, Huawei cloud sky chip AI solver once again topped the international authoritative list
High energy live broadcast, a gathering of celebrities! We invite you to explore bizdevops.
「运维有小邓」审核并分析文件和文件夹访问权限
leetcode:238. 除自身以外数组的乘积