SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    Non-Member
    Join Date
    Aug 2007
    Posts
    494
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Problem with INNER JOIN syntax

    Hi all.

    My three tables in the db MYSQL:

    Code:
    TBL_MASTER
    ID	TYPE
    1	RG
    2	CO
    3	RG
    4	RG
    5	RG
    6	CO
    7	CO
    
    
    TBL_RG
    ID	ID_MASTER
    1	1
    2	3
    3	4
    4	5
    
    
    TBL_CO
    ID	ID_MASTER
    1	2
    2	6
    3	7
    Whit this query I see the rows in the tbl_master and in the tbl_rg:

    Code:
       
       SELECT * FROM 
          tbl_master 
       INNER JOIN 
          tbl_rg ON 
             tbl_rg.ID_MASTER = tbl_master.ID

    I need see the rows of the tbl_co with same and only query SQL... it's possible?

    Can you help me?
    kind regards
    viki

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,499
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    Code:
    SELECT * FROM 
          tbl_master 
       INNER JOIN 
          tbl_rg ON 
             tbl_rg.ID_MASTER = tbl_master.ID
    UNION
    SELECT * FROM 
          tbl_master 
       INNER JOIN 
          tbl_co ON 
             tbl_co.ID_MASTER = tbl_master.ID
    But I fail to see the usefulness of the RG and CO table. I hope it's just an example

  3. #3
    Non-Member
    Join Date
    Aug 2007
    Posts
    494
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks x your reply.

    This three tables are different with differents dates....

    In the TBL_MASTER I see:

    Code:
    TBL_MASTER
    ID	TYPE	DATE
    1	RG	2008-11-20
    2	CO	2008-11-19
    3	RG	2008-11-18
    4	RG	2008-11-19
    5	RG	2008-11-11
    6	CO	2008-11-10
    7	CO	2008-11-10
    In the TBL_RG I see:

    Code:
    TBL_RG
    ID	ID_MASTER	NAME
    1	1		JACK
    2	3		WILLY
    3	4		SEAN
    4	5		PATTY
    In the TBL_CO I see:

    Code:
    TBL_CO
    ID	ID_MASTER	NAME	
    1	2		PETER
    2	6		ROXY
    3	7		PHIL
    And I need see this differents dates with only query SQL...

    it's Ok ?

  4. #4
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,260
    Mentioned
    60 Post(s)
    Tagged
    3 Thread(s)
    viki, i understand that english is not your first language, but your question is not clear

    for the sample data that you showed in post #3, please show the results that you want to receive from the query
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  5. #5
    Non-Member
    Join Date
    Aug 2007
    Posts
    494
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes r937 english is not my first language... sorry...

    Show the results I want to receive from the single query:

    Code:
    1	RG	2008-11-20	JACK
    2	CO	2008-11-19	PETER
    3	RG	2008-11-18	WILLY
    4	RG	2008-11-19	SEAN
    5	RG	2008-11-11	PATTY
    6	CO	2008-11-10	ROXY
    7	CO	2008-11-10	PHIL
    it's Ok ?

    PS: I voted...

  6. #6
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,260
    Mentioned
    60 Post(s)
    Tagged
    3 Thread(s)
    this is basically guido's query -- note, i used UNION ALL
    Code:
    SELECT m.id
         , m.type
         , m.date
         , rg.name
      FROM tbl_master AS m
    INNER 
      JOIN tbl_rg AS rg
        ON rg.id_master = m.id
    UNION ALL
    SELECT m.id
         , m.type
         , m.date
         , co.name
      FROM tbl_master AS m
    INNER 
      JOIN tbl_co AS co
        ON co.id_master = m.id
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  7. #7
    Non-Member
    Join Date
    Aug 2007
    Posts
    494
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks!


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
  •