Jump to content

MYSQL Query Help


dlebowski

Recommended Posts

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!

Link to comment
https://forums.phpfreaks.com/topic/209271-mysql-query-help/
Share on other sites

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`

Link to comment
https://forums.phpfreaks.com/topic/209271-mysql-query-help/#findComment-1092817
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.