Hi,
I am wanting to display information on a webpage about asset distribution.
I have 3 tables, there are tb_users , tb_assets and tb_distribution.
within the tb_users table it references tb_distribution through an id_user and tb_distribution table references tb_asset through an serial_number which coresponds to a record within tb_distribution and tb_asset tables.
i want to obtain all of this information so that i can display it all on the webpage.
I have used JOIN to do part of this shown below:
SELECT tb_users.*, tb_distribution.*
FROM tb_users
INNER JOIN tb_distribution
ON tb_users.id_user = tb_distribution.id_user
WHERE tb_users.id_user = ’047923′I want to be able to include tb_asset in the statement aswell so that i can use it to display it on the webpage.
anyone know how i can obtain all the infromation from all tables in one SQL statement.
Thanks
Jane
Ada saat-saat dimana lebih dari dua tabel harus bergabung untuk menampilkan hasil yang diinginkan. Seperti pada kasus diatas, dimana SQL join biasa tidak dapat diterapkan. Maka untuk hal ini, menggabungkan 3 tabel atau lebih dapat diatasi dengan menggunakan Multiple SQL Joins.
Penggunaan Multiple SQL Joins pada kasus diatas dapat dilihat pada contoh dibawah ini :
SELECT tb_users.*, tb_distribution.*, tb_assets.*
FROM (tb_users
INNER JOIN tb_distribution
ON tb_users.id_user = tb_distribution.id_user) INNER JOIN tb_assets ON tb_distribution.serial_number = tb_assets.serial_number
WHERE tb_users.id_user = ’047923′
see? just as simple as that
and you can apply this query for 3, 4 or more tables…
Happy Trying
Posted by ocha on March 21, 2010 at 3:52 pm
keep write!
Posted by rahminovita on March 21, 2010 at 6:22 pm
thx ocha (cozy)
Posted by Neng Ucrit on April 7, 2010 at 2:33 pm
khud.. tapi contoh tablenya sama tampilannya dunk
Posted by rahminovita on June 22, 2010 at 5:37 pm
hmmm ok deh, nanti diusahain yah neng ucrit, thx masukannya
Posted by neng ucrit on February 11, 2011 at 2:55 pm
very usefull, berkali2 pk ini gw
Posted by rahminovita on February 21, 2011 at 6:47 am
so do i dear, very usefull too for me