Hey there! Sign in to join this conversationNew here? Join for free
    • Thread Starter
    Offline

    1
    ReputationRep:
    Hello,

    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?

    Thanks
    Offline

    0
    ReputationRep:
    yeah use a join statement
    http://sqlzoo.net/3b.htm
    Offline

    0
    ReputationRep:
    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
    Offline

    1
    ReputationRep:
    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
    Ideally you want to use foreign keys where the tables are joined but not all Databases / Table types support foreign keys properly.

    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.
 
 
 
  • See more of what you like on The Student Room

    You can personalise what you see on TSR. Tell us a little about yourself to get started.

  • Poll
    What newspaper do you read/prefer?
    Useful resources
  • See more of what you like on The Student Room

    You can personalise what you see on TSR. Tell us a little about yourself to get started.

  • The Student Room, Get Revising and Marked by Teachers are trading names of The Student Room Group Ltd.

    Register Number: 04666380 (England and Wales), VAT No. 806 8067 22 Registered Office: International House, Queens Road, Brighton, BN1 3XE

    Quick reply
    Reputation gems: You get these gems as you gain rep from other members for making good contributions and giving helpful advice.