Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Sep 2002
    Posts
    462
    Thanks
    0
    Thanked 20 Times in 20 Posts

    general JOIN question

    I don't understand joining using mysql so this may sound off...

    I have 2 tables: example
    companies
    id | name
    1 | joe's pub


    people
    id | name | email | companyid
    1 | joe | whatever | 1


    I need to get the entire list from the 'people' table but I also need the name of the company they work for!???

    All the things I've seen online join multiple tables in a strange way.
    NO Limits!! DHCreationStation.com
    ------------------------------------------------------------
    For projects using MediaTypes (MIMETypes) visit E-BAM.net -(updated weekly)

    Broken items wanted for tinkerin'! PostItNow@BrokenEquipment.com
    Global Complaint Dept.

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    Single join is more than sufficient:
    Code:
    SELECT p.name, p.email, c.name
    FROM people p
    INNER JOIN companies c ON c.id = p.companyid
    Use a left join if its possible for companyid to be null.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • #3
    Regular Coder
    Join Date
    Sep 2002
    Posts
    462
    Thanks
    0
    Thanked 20 Times in 20 Posts
    thanks for the help Lu, that worked!
    But I still need the 'companyid' number to run a process with so how can I modify your code to get companyid number in the main 'people' listing?

    nevermind I figured it out! yeh!! Again thanks for the help!!!
    Last edited by c1lonewolf; 01-11-2014 at 06:33 PM.
    NO Limits!! DHCreationStation.com
    ------------------------------------------------------------
    For projects using MediaTypes (MIMETypes) visit E-BAM.net -(updated weekly)

    Broken items wanted for tinkerin'! PostItNow@BrokenEquipment.com
    Global Complaint Dept.


  •  

    Posting Permissions

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