By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,009 Members | 1,885 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,009 IT Pros & Developers. It's quick & easy.

How to show five tables in same code

P: 2
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.
Sep 11 '14 #1

✓ answered by emailhosting

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.

Expand|Select|Wrap|Line Numbers
  1. 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.




------------------------

Share this Question
Share on Google+
2 Replies


P: 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.

Expand|Select|Wrap|Line Numbers
  1. 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.




------------------------
Sep 17 '14 #2

P: 2
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.
Sep 21 '14 #3

Post your reply

Sign in to post your reply or Sign up for a free account.