SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    John 8:24 JREAM's Avatar
    Join Date
    Sep 2007
    Location
    Florida
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    What happens when you INNER JOIN again?

    I forgot this or maybe never totally understood it.

    Lets say you have two tables, both have different Primary Key ID's,


    If you INNER JOIN the table,
    Which tables Primary Key ID's are preserved, and which are combined in?

    Does that make sense? Or does it make a new set of Primary Key ID's?

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,510
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    INNER JOIN on what? There has to be a connection between the two tables, or it would become a CROSS JOIN.
    And what do you mean by 'preserved'? The query will return the columns that you specify in the SELECT.

  3. #3
    John 8:24 JREAM's Avatar
    Join Date
    Sep 2007
    Location
    Florida
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you I couldnt find this post anywhere and I found it now.


    Lets say you have these two tables:


    Code:
    
    Age Table
    
    id        age            person_id
    -------------------------------
    0        36                0
    1        33                2
    2        22                3
    7        33                1
    8        22                3
    
    
    
    Persons Table (uses the Foreign Key from person_id)
    
    id        name
    -------------------------------
    0        mark
    1        harry
    2        jim
    3        fred
    4        jeff

    If you do:
    Code MySQL:
    SELECT * FROM age
    INNER JOIN persons 
    ON (
    age.person_id = persons.id 
    )
    It would list the ID's from the AGE table since that's where we are selecting it from?

    In other words, the two tables line up based on a match and creates one row, but what are these new rows ID's based on?

  4. #4
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,510
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    Since you use SELECT *, all columns from both tables are selected.
    The rows in the query result don't get a new PK.
    And since there's a field called 'id' in both tables, you'd have to execute the query and see how those are called in the query result.


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
  •