webguync Posted June 24, 2008 Share Posted June 24, 2008 I have a table Join Query $sql = "SELECT ID, emp_name, emp_id FROM $employee_table LEFT JOIN $check_table ON `ID` = `EmpID` ORDER BY ID ASC"; and I want to add another column to Join,so it would be ON `emp_name` = `EmpName` would I need to do a separate $sql or can I combine what I have above somehow? Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted June 24, 2008 Share Posted June 24, 2008 that is bad table structure if you need to join like that. Key to Key joins are best. explain your reasoning Quote Link to comment Share on other sites More sharing options...
webguync Posted June 25, 2008 Author Share Posted June 25, 2008 well, I have another post http://www.phpfreaks.com/forums/index.php/topic,203543.0.html on the PHP forums, explaining what I am trying to accomplish posting information from a select form. I thought another join might be what I need, but I didn't know for sure, or even if it was possible. Quote Link to comment Share on other sites More sharing options...
fenway Posted June 25, 2008 Share Posted June 25, 2008 You can combine multiple conditions in the ON clause like in a WHERE clause. Quote Link to comment Share on other sites More sharing options...
webguync Posted June 26, 2008 Author Share Posted June 26, 2008 would that be something like $sql = "SELECT ID, emp_name, emp_id FROM $employee_table LEFT JOIN $check_table ON `ID` = `EmpID` AND ON `emp_name` = `EmpName`ORDER BY ID ASC"; ?? Quote Link to comment Share on other sites More sharing options...
fenway Posted June 26, 2008 Share Posted June 26, 2008 No... like "ON ( `ID` = `EmpID` AND `emp_name` = `EmpName` )" Quote Link to comment Share on other sites More sharing options...
webguync Posted June 26, 2008 Author Share Posted June 26, 2008 ok, thanks Quote Link to comment 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.