Jump to content

Left join and Where


khefner

Recommended Posts

Ok here goes:

I have a php page with Mysql that is using a left join. ( That works correctly.)

 

$query_partdata = "SELECT electrical_BOM.itemnumber,electrical_BOM.description, electrical_BOM.code,  parts.partnumber, parts.parttype, parts.package , parts.manufacturer, parts.screenlevel, parts.quallevel, parts.totaldoselevel, parts.seulevel, electrical_BOM.quantity, electrical_BOM.whereused, parts.parnumber
From electrical_BOM LEFT JOIN parts ON electrical_BOM.itemnumber = parts.itemnumber";

Ok so I have two tables, electrical_BOM and parts

Per the LEFT JOIN function all of the records from electrical_BOM are displayed after being joined with certain fields from parts.(This works ok, I output it to the screen)

 

However I would like to somehow use a WHERE or other technique in which I only obtain the records in electrical_BOM when the field  "code" (Which is in electrical_BOM) is equal to the number 2 or 3.

 

I dont know how to use the LEFT JOIN in conjunction with the WHERE. Maybe there is a better way of doing this than using a LEFT JOIN?

Thanks

 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/94019-left-join-and-where/
Share on other sites

<?php
$query_partdata = "SELECT electrical_BOM.itemnumber,electrical_BOM.description, electrical_BOM.code,  
                    parts.partnumber, parts.parttype, parts.package , parts.manufacturer, 
                    parts.screenlevel, parts.quallevel, parts.totaldoselevel, parts.seulevel, 
                    electrical_BOM.quantity, electrical_BOM.whereused, parts.parnumber
                   FROM electrical_BOM 
                        LEFT JOIN parts ON electrical_BOM.itemnumber = parts.itemnumber
                   WHERE electrical_BOM.code IN (2,3)";      

Link to comment
https://forums.phpfreaks.com/topic/94019-left-join-and-where/#findComment-482097
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.