1
我想在同一時間我也想獲得c.category選擇DISTINCT(p.ptype)如果p.ptype不在集c.ptype使用DISTINCT與FIND_IN_SET
數據庫表:p
id ptype
1 Shirts
2 Cups
3 Shirts
4 Mugs
數據庫表格:C
id category ptype
1 Test Pants, Shirts, TShirts
2 Test1 Cups, Mats, Rugs
我嘗試的SQL命令如下
SELECT DISTINCT(p.ptype), IF(FIND_IN_SET(p.ptype, c.ptype), c.category,'') as category
FROM p, c
這輸出設置兩次的p.ptype。一次使用空的c.category字段,另一次使用填充的c.category。
但是期望的輸出如下
ptype category
Shirts Test
Cups Test1
Mugs