douyu9159 2015-01-27 00:10
浏览 42
已采纳

mysql函数,返回名称而不是id

Hi I have Table tbl_itemlist with

id | itemName | suppliers
1  | uSDReader| 1,2,3,4,5 

the suppliers column contains comma delimited value ex: (1,2,3,4,5)

Which correspond to suppliers name from other table tbl_supplier

id | supplierName
1  | Supplier 1
2  | Supplier 2
3  | Supplier 3
4  | Supplier 4
5  | Supplier 5

Is there any builtin function of MySQL that when I query using SELECT the itemlist table, something like JOINs, supplier column will return the name instead of supplier's id only. ex:

 id | itemName | suppliers
 1  | uSDReader| Supplier 1,Supplier 2,Supplier 3,Supplier 4,Supplier 5
  • 写回答

1条回答 默认 最新

  • douju6651 2015-01-27 00:40
    关注

    You indeed have a really bad MySQL schema. You have to create 3 tables named as tbl_itemlist, tbl_suppliers, tbl_itemsupplies.

    tbl_itemslist and tbl_suppliers are the same as yours with tbl_itemslist with suppliers column deleted.

    Your new table, tbl_itemsupplies, must contain these exact columns: id, item_id, supplier_id

    You can check which suppliers does have the item with a simple query like:

    SELECT `supplier_id` FROM tbl_itemsupplies WHERE `item_id`= {$itemid}
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀