AdRock Posted November 20, 2014 Share Posted November 20, 2014 I have 2 queries that I want to join together to make one row This queries returns all rows from both tables which is what i want SELECT table_A.*, table_B.* FROM table_A INNER JOIN table_B ON table_A.code = table_B.code and this is the output table_A.id | table_A.code | table_B.id | table_B.code | table_B.complete =============================================================================================== 1 | 123456 | 1 | 123456 | yes 2 | 654321 | 2 | 654321 | no and this is the second query SELECT table_C.*, table_D.* FROM table_C INNER JOIN table_D ON table_C.code = table_D.code INNER JOIN table_B ON table_D.code = table_B.code WHERE table_B.complete = 'yes' and again the output table_C.id | table_C.code | table_D.id | table_D.field2 | table_B.complete ======================================================================================== 1 | 123456 | 1 | 123456 | yes What I've been trying to for the last couple of days is join the 2 queries together to make one query that returns this table_A.id | table_A.code | table_B.id | table_B.code | table_B.complete | table_C.id | table_C.code | table_D.id | table_D.field2 | table_B.complete ==================================================================================================================================================================================== 1 | 123456 | 1 | 123456 | yes | 1 | 123456 | 1 | 123456 | yes 2 | 654321 | 2 | 654321 | no All i want it to do is get all rows from tables A and B and return all rows from C and D only if table_B.complete equals "yes". All tables are joined by the code column which all have the same value Quote Link to comment https://forums.phpfreaks.com/topic/292590-select-all-rows-from-tables-joining-other-table-but-select-only-rows-that-match-a-condition/ 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.