Multiple SQL Joins

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

and you can apply this query for 3, 4 or more tables…

Happy Trying :)

6 responses to this post.

  1. keep write! ;)

    Reply

  2. khud.. tapi contoh tablenya sama tampilannya dunk :D

    Reply

  3. very usefull, berkali2 pk ini gw :D

    Reply

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.