我正在我的平臺內制作搜索引擎,我想搜索名為 的特定表business_services,該表包含來自另一個名為 的表的外鍵services。
每個企業都提供其中一些服務的想法,但我只將服務 ID 存盤在business_services表中。
我如何business_services在使用名稱搜索時僅使用它的 ID來搜索服務表
如果這是不可能的,我可以在business_services表中創建另一列來存盤服務名稱,但如何在服務名稱更改時更新該名稱
商業
| id | name_en | name_fr | status |
|-----|---------|---------|--------|
| 134 | name 1 | nom 1 | 1 |
| 432 | name 2 | nom 2 | 1 |
| 325 | name 3 | nom 3 | 2 |
服務
| id | name_en | name_fr | status |
|----|-----------|-----------|--------|
| 5 | service 1 | service 1 | 1 |
| 9 | service 2 | service 2 | 1 |
| 4 | service 3 | service 3 | 1 |
商業服務
| id | business_id | service_id | status |
|----|-------------|------------|--------|
| 1 | 134 | 5 | 1 |
| 2 | 432 | 9 | 1 |
| 3 | 325 | 4 | 1 |
uj5u.com熱心網友回復:
如果您正在尋找名為 service 1 的服務 fr 名稱的示例。
select
bs.*, -- all columns from business_services
-- columns from services table
s.name_en,
s.name_fr,
s.status
from
business_services bs inner join services s on bs.service_id=s.id
where
s.name_fr = 'service 1';
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/403157.html
標籤:
