As part of my assignment I need to create a database with some tables in MySQL/PHPMyAdmin. I have a table containing workplaces and then I have a table with staff in too, what I want to do is reference the workplace location (from the workplace table) in the staff table.
If that makes sense? Or is even possible?
MySql help Watch
- Thread Starter
- 05-12-2010 15:33
- 05-12-2010 15:37
yeah use a join statement
- 05-12-2010 22:47
You're not clear with what exactly you want - do you mean in query, or you just want to link the 2? You'll need a foreign key to do that
- 06-12-2010 00:55
You can do it but how you do it depends on what you need to achieve. However you do it you need some sort of key to link to in the relevant tables. Ideally you have a primary key which is an incrementing number that has no other meaning.
If a member of staff can only ever work in one workplace then you can do it with the two tables you described.
If a member of staff could work in multiple workplaces you'll need three tables. The two you've described and a table that can link them together.
To link the tables together to get the complete set of results out you'll need to join the tables in pseudo SQL it's something like:Code:
SELCT a.foo,b.bar FROM a JOIN b on b.id=a.workplace where Blah
Best way to find out how to make it work is to put some data into a database and play around with it to find out how to get the results you need. The documentation on the MySQL site can be good as well for some of this.