dlebowski Posted July 29, 2010 Share Posted July 29, 2010 Below are my two tables. What I want to do is get the values out of table 1 and out of table two that meet the following criteria: If the Buyer in table 1 matches the Buyer value in table 2, I want all the matching Lot information out of table 1. Out of table 2, I just want the values that DO NOT not have a matching Buyer value in table 1. For example: 1 | Stuff 1 | 8 | 2222 2 | Stuff 2 | 5 | 333 3 | Stuff 3 | 9 | 888 4 | Stuff 4 | 1 | 2222 2 | 2 | 2222 3 | 2 | 2222 Basically, "If table1.buyer=table2.buyer, return all matching information from table 1". "If table1.Buyer does not match table2.buyer, return all non matching information from table 2". Table 1 Lot | Title | Price | Buyer -------------------- 1 | Stuff 1 | 8 | 2222 2 | Stuff 2 | 5 | 333 3 | Stuff 3 | 9 | 888 4 | Stuff 4 | 1 | 2222 Table 2 Lot | Your Price | Buyer -------------------- 1 | 12 | 2222 2 | 2 | 2222 3 | 2 | 2222 4 | 14 | 2222 Thank you for your help! Quote Link to comment https://forums.phpfreaks.com/topic/209271-mysql-query-help/ Share on other sites More sharing options...
petroz Posted July 29, 2010 Share Posted July 29, 2010 You can do it like this SELECT * from `table1`,`table2` WHERE `table1`.`id` = `table2`.`id` I would recommend being explicit in the information you are returning. For example SELECT `table1`.`column2`, `table1`.`column3` FROM `table1`,`table2` WHERE `table1`.`id` = `table2`.`id` Quote Link to comment https://forums.phpfreaks.com/topic/209271-mysql-query-help/#findComment-1092817 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.