How to show five tables in same code

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ujoehero
    New Member
    • Sep 2014
    • 2

    How to show five tables in same code

    Hi!

    Sorry for my bad english in advance...
    So, I have five tables (rpg_swords, rpg_armors, rpg_sheilds, rpg_users and rpg_potions) and I have that code:

    <code>SELECT nume, item_code, iconita
    FROM rpg_rpg_licori, rpg_rpg_users
    WHERE item_code
    IN (2,3,4,5,6,7,8, 9,10,11,12)
    GROUP BY item_code</code>

    // That array (2,3,4,...) is just an exemple

    Now, i want to create a code where result same thing but with the rest of the tables in the same code.

    Sorry, I`m newbie in sql. I searched and probably I found but i don`t know how to proceed.
  • emailhosting
    New Member
    • Sep 2014
    • 2

    #2
    Hello ujoehero,

    If you would like to fetch related datas from multiple tables in a single query. You may use the JOIN syntax. See the following case:

    Let say we have:
    table_one with the following columns/fields:
    • item_id
    • item_name
    • item_desc


    table_two with the following columns/fields:
    • item_id
    • column_one
    • column_two


    table_three with the following columns/fields:
    • item_id
    • column_three
    • column_four


    Here is the example query you can use to fetch relative records from multiple tables using JOIN syntax.

    Code:
    SELECT table_one.item_id, table_one.item_name, table_one.item_desc, table_two.column_one, table_two.column_two, table_three.column_three, table_three.column_four FROM table_one LEFT JOIN table_two ON table_two.item_id = table_one.item_id LEFT JOIN table_three ON table_three.item_id = table_one.item_id WHERE table_one.item_id IN (2,3,4,5,6,7,8,9,10,11,12);
    Hope this helps you.




    ------------------------
    Last edited by Rabbit; Sep 17 '14, 04:16 AM. Reason: Self promotional link removed

    Comment

    • ujoehero
      New Member
      • Sep 2014
      • 2

      #3
      Thank you! I found solution in an old book of sql/mysql, but I thank you! If I can reward you somehow, just say. :) You are the only guy who respond on that question in one week.

      Comment

      Working...