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"