Jump to content

SELECT from 2 tables


medj

Recommended Posts

Hopefully someone can help me out with this.

 

I have a database with 2 tables. I simply would like to perform a query that will display the rows where the "Part Number" of the first table matches the "Manufacturing Number" of the second one. This works out fine for me since I'm using this code:

 

$function_match = mysql_query( "SELECT * FROM components, bom_dimwheel_white WHERE `components`.`part_num` = `bom_dimwheel_white`.`manufacturer_num`" )
or die("SELECT Error: ".mysql_error());

 

 

I have about 20 column/fields in "components" and 10 in "bom_dimwheel_white". When I display my results of the query, I am getting all 30 fields being displayed when all I want is to show the results of the components table. What I mean is that the display should only have the 20 field columns from the 'components' table.

 

Can anyone help me out?

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

When using an JOIN you'll need to use GROUP BY to prevent duplicate results. So use:

$function_match = mysql_query( "SELECT * FROM components, bom_dimwheel_white WHERE `components`.`part_num` = `bom_dimwheel_white`.`manufacturer_num` GROUP BY `components`.`part_num`" )
or die("SELECT Error: ".mysql_error());

Link to comment
https://forums.phpfreaks.com/topic/109010-select-from-2-tables/#findComment-559907
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.