Close

Results 1 to 7 of 7
  1. #1
    DF VIP Member big man's Avatar
    Join Date
    Jul 2002
    Location
    The big smoke
    Posts
    2,824
    Thanks
    8
    Thanked:        0
    Karma Level
    445

    Default Linking tables in mySQL

    This might seem like a simple question, but i'm new to this.............

    how do you link tables in mySQL. I have a name_id set as a primary key in one table, and then i have a name_id field in each of my other tables. How do i create the relationship between these??

    Thanks for any help guys

    Big man
    I am a loud man with a very large hat. This means I am in charge

    Never argue with an idiot. They will bring you down to their level, then beat you with experience.

  2. #2
    DF VIP Member molacka's Avatar
    Join Date
    Apr 2001
    Location
    Newcastle
    Posts
    251
    Thanks
    0
    Thanked:        0
    Karma Level
    304

    Default

    You have already created the relationship by having the primary key of one table as the foreign key in another. You've now got to reference the fields you want in the query and where they match:

    SELECT tbl_Main.name_first, tbl_Main.name_second, tbl_Account.account_no, tbl_Account.blah...
    FROM tbl_Main, tbl_Account
    WHERE tbl_Main.name_id = tbl_Account.name_id

    that's about it really, unless you want to get into INNER, OUTER or NATURAL joins which take a bit more explaining

  3. #3
    DF VIP Member big man's Avatar
    Join Date
    Jul 2002
    Location
    The big smoke
    Posts
    2,824
    Thanks
    8
    Thanked:        0
    Karma Level
    445

    Default

    I see - thanks for the help. I think i can get my head round this now
    I am a loud man with a very large hat. This means I am in charge

    Never argue with an idiot. They will bring you down to their level, then beat you with experience.

  4. #4
    DF Rookie cockneywanka's Avatar
    Join Date
    Oct 2002
    Location
    london
    Posts
    9
    Thanks
    0
    Thanked:        0
    Karma Level
    0

    Default SQl Join

    you need to do an SQL join

    something like

    SELECT * from Customer c, Order o
    WHERE c.customer_id=o.customer_id

    this would get all columns from Customer, Order tables
    where the customer_id key fields match in both tables

    best get a book on SQL as the above example is a fairly simple
    example

    hth

    cw

  5. #5
    DF VIP Member funy's Avatar
    Join Date
    Mar 2001
    Location
    East Sussex
    Posts
    123
    Thanks
    0
    Thanked:        0
    Karma Level
    0

    Default

    If your talking books you should get

    MySQL by Paul Dubois - ISBN: 0-7357-0921-1

    I believe amazon should have it.

    I learned everything i needed to know from there.


    There may be books that go deeper but this is a great book for starters and for reference.
    "Erm, I think we're losing sight of the real issue here, which is 'What are we gonna call ourselves?' Erm, and I think it comes down to a choice between 'The League Against Salivating Monsters' or my own personal preference, which is 'The Committee for the Liberation and Integration of Terrifying Organisms and their Rehabilitation Into Society'. Erm, one drawback with that - the abbreviation is 'CLITORIS'." - Rimmer - Polymorph
    my box: amd athlon xp2200+ // 512mb ddr // gf4 ti4600 // winxp pro

  6. #6
    DF VIP Member mladen's Avatar
    Join Date
    Jan 2002
    Location
    Cheltenham
    Posts
    2,005
    Thanks
    4
    Thanked:        1
    Karma Level
    390

    Default

    I agree, you could do worse than to get a book

    I have 3 on sql and php
    Mladen

  7. #7
    DF VIP Member big man's Avatar
    Join Date
    Jul 2002
    Location
    The big smoke
    Posts
    2,824
    Thanks
    8
    Thanked:        0
    Karma Level
    445

    Default

    Treated myself to a couple of those beginner - Teach youself books.

    Very useful. I think i'm getting there now

    Cheers guys
    I am a loud man with a very large hat. This means I am in charge

    Never argue with an idiot. They will bring you down to their level, then beat you with experience.

Similar Threads

  1. Looking for PHP (no mysql) script!
    By itschris in forum Website Coding & Graphics
    Replies: 3
    Last Post: 5th March 2003, 11:47 AM
  2. Linking Two Xbox Machines To Back One Up
    By ZOOT in forum Microsoft Consoles
    Replies: 3
    Last Post: 18th February 2003, 02:20 AM
  3. PHP & MySQL
    By g1bbo in forum Website Coding & Graphics
    Replies: 6
    Last Post: 20th December 2002, 05:34 PM
  4. Restaurant uses naked girls as tables
    By cronus71 in forum The Dog and Duck
    Replies: 16
    Last Post: 7th November 2002, 04:15 PM
  5. Small question on MS SQL, MySql and MS ACCESS
    By H@z in forum The Dog and Duck
    Replies: 1
    Last Post: 7th October 2002, 12:45 PM

Social Networking Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •