What's faster

Discussion in 'MySQL' started by sky22, Apr 29, 2007.

  1. #1
    Hello,

    I'm using MySQL and I have two tables that look like this:

    table a
    +---+------+-----+
    | ID | Name | ECT |
    +---+------+-----+

    and table b

    +---+------+-----+
    | ID | Name | ECT |
    +---+------+-----+

    What I want to do is get all the names from table a where the id is 1 and all the names from table b where id is 1. But would it be faster to use two separate select query's or or one join query?

    Sorry if this is a stupid question just I'm not sure if joining tables is only for complex query's or if it's fast.

    Thanks for any help :D
     
    sky22, Apr 29, 2007 IP
  2. lukejea

    lukejea Guest

    Messages:
    62
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Actually, making a join command would be faster bescause the program would not have to make a second round trip to the database with that separate select query.

    :D

    hope that helped
     
    lukejea, Apr 29, 2007 IP
  3. sky22

    sky22 Guest

    Messages:
    59
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks for the help :)
     
    sky22, Apr 29, 2007 IP
  4. SoKickIt

    SoKickIt Active Member

    Messages:
    305
    Likes Received:
    30
    Best Answers:
    0
    Trophy Points:
    70
    #4
    JOIN doesn't make sense in this example and you won't get what you need that way. Use UNION:

    SELECT name FROM a WHERE id = 1 UNION SELECT name FROM b WHERE id = 1
    Code (markup):
     
    SoKickIt, Apr 30, 2007 IP
  5. ruby

    ruby Well-Known Member

    Messages:
    1,854
    Likes Received:
    40
    Best Answers:
    1
    Trophy Points:
    125
    #5
    Yes that what I would do.... a UNION.
     
    ruby, Apr 30, 2007 IP
  6. sky22

    sky22 Guest

    Messages:
    59
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Thanks so much for the help, saved me getting a headache trying to work that out :D
     
    sky22, Apr 30, 2007 IP