khefner Posted March 2, 2008 Share Posted March 2, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/94019-left-join-and-where/ Share on other sites More sharing options...
Barand Posted March 3, 2008 Share Posted March 3, 2008 <?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)"; Quote Link to comment https://forums.phpfreaks.com/topic/94019-left-join-and-where/#findComment-482097 Share on other sites More sharing options...
khefner Posted March 3, 2008 Author Share Posted March 3, 2008 Thanks Barand that worked perfectly. SQL is amazing...! Quote Link to comment https://forums.phpfreaks.com/topic/94019-left-join-and-where/#findComment-482101 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.