如何将带有前缀列的表连接到 PHP MySQL 或 Laravel 中的另外两个表

Posted

技术标签:

【中文标题】如何将带有前缀列的表连接到 PHP MySQL 或 Laravel 中的另外两个表【英文标题】:How to join table with prefix column to another two table in PHP MySQL or Laravel 【发布时间】:2021-02-18 16:38:03 【问题描述】:

这是否可以将join table 的前缀列添加到mysql 中的另外两个table例如第一个Customer IDName 列和第二个Supplier IDName 列和第三个Purchase 有列IDProductParty 我想将这三个表 Purchase tableParty 加入到 table CustomerSupplierID 这里cus_ 的意思是ID 表格Customer 和 这里sup_ 的意思是ID 形式Supplier任何人都可以解决这个加入吗?无前缀 Customer Supplier 表格 PRIMARY KEY

【问题讨论】:

【参考方案1】:

加入客户表:

select * from purchase_table pt inner join Customer c on 
select replace(pt.party,'cus_','')=c.id and pt.party like 'cus_%'

加入供应商表:

select * from purchase_table pt inner join Supplier s on 
select replace(pt.party,'sup_','')=s.id and pt.party like 'sup_%'

【讨论】:

以上是关于如何将带有前缀列的表连接到 PHP MySQL 或 Laravel 中的另外两个表的主要内容,如果未能解决你的问题,请参考以下文章