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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.