giraffemedia Posted August 7, 2008 Share Posted August 7, 2008 Hello is it possible to select rows from one table where the data contained in a column is equal to that of another table? i.e SELECT * FROM test1 WHERE test1.column1 = test2.column3 Thanks James Quote Link to comment Share on other sites More sharing options...
fenway Posted August 7, 2008 Share Posted August 7, 2008 Sure... SELECT test1.* FROM test1 INNER JOIN test2 ON (test1.column1 = test2.column3) Quote Link to comment Share on other sites More sharing options...
giraffemedia Posted August 7, 2008 Author Share Posted August 7, 2008 Thanks fenway. i've tried it, and it sort of works but it's duplicating one result rather than each one being different. Regards James Quote Link to comment Share on other sites More sharing options...
fenway Posted August 7, 2008 Share Posted August 7, 2008 i've tried it, and it sort of works but it's duplicating one result rather than each one being different. Is this a 1-to-1 relationship? Quote Link to comment Share on other sites More sharing options...
giraffemedia Posted August 8, 2008 Author Share Posted August 8, 2008 i've tried it, and it sort of works but it's duplicating one result rather than each one being different. Is this a 1-to-1 relationship? Do you mean does one record from one table relate to just one from the other fenway? If that's the case then no - there are multiple rows from the booking_form table that relate to a specific row from the contacts table. Each time a new booking for the same client (from the contacts table) gets entered as a new row with an auto_incremental id. So there can be 1-many rows for each contact. Hope this helps. James Quote Link to comment Share on other sites More sharing options...
fenway Posted August 9, 2008 Share Posted August 9, 2008 Well, that does explain why you're getting multiple values... do you really want * back? Is the * from the "1" table or the "many" table? Quote Link to comment Share on other sites More sharing options...
giraffemedia Posted August 11, 2008 Author Share Posted August 11, 2008 fenway, i've got it to work by using the following. $find_issues_query = "SELECT * FROM booking_form b INNER JOIN contacts c ON b.bf_company_id = c.contacts_id WHERE b.bf_company_id = c.contacts_id ORDER BY b.bf_id" or die(0); Thanks for your help James 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.