mysql table id,MySQL联接两个表ID以产生从一个表到另一个表的结果

I've tried a whole slew of examples / answered questions on stackoverflow but I can't seem to accomplish what I need.

I have a PHP / MySQL tool I'm working on to track projects for myself. I thought it'd be a good idea to optimize the largest table right off the hop, so I chose to store ID's in the Project table as opposed to full names. I'm looking to link that ID from the Project table to the actual Name in another table when viewing results via PHP, but of course I want the actual database column to just contain the ID. I believe this is possible, I just can't figure out how to apply it to my situation.

Table - Projects

ID | CustomerID | Summary | Phase

---------------------------------

1 | 61 | Project1 | 3

2 | 42 | Project2 | 3

3 | 33 | Project3 | 5

Table - Customers

ID | CustomerName

--------------------

61 | Customer 1

42 | Customer 2

33 | Customer 3

Right now when I call the "CustomerID" row from the Projects Table, it displays the CustomerID number as expected. I would like it to pull the CustomerName from the Customers table instead, matching the Customers.ID column to the Projects.CustomerID column.

Is this possible? Can anyone point me in the right direction?

Thanks in advanced!

解决方案

You can try something like this:

SELECT CustomerName FROM Projects

JOIN Customers ON Customers.ID = Projects.CustomerID

WHERE Projects.ID = "1"

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值