Jump to content

Selecting from 2 tables


medj

Recommended Posts

I have 2 tables called 'components' and 'bom'.

 

My 'components' table has 10 columns. (~100 rows)

My 'bom' has 6 columns. (~12 rows)

 

There is one column in the 'bom' table that has same value as one of the columns in the 'components' table. I would like to match this 'bom' column against the component column.

 

I do know how to do this already with a query such as the following:

 

SELECT `components`.`part_num`, `components`.`name`  FROM `components` WHERE `components`.`part_num` IN 
(SELECT `bom`.`number` FROM `bom`)

 

This is my problem that I am facing:

I would like to be able to display all column data on the page.

For example, I have 10 + 6 = 16 columns of data from both tables.

I would like to display all the data from both tables.

 

I already know the php code to display data from rows. For instance, I am able to display the 'part_num' and 'name' of all the components table for the 12 rows of the 'bom'. I can add more of these if I wanted to show the 10 rows from the components table. The main problem is that I would like to display the other 6 columns of data from the 'bom' table and I have tried many different alternations of the query but can't seem to make it work.

 

Any help please?

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/117753-selecting-from-2-tables/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.