I have two tables. I want to join them in a way that only one record in the right table is returned for each record in the left most table. I've included an example below. I'd like to avoid subqueries and temporary tables as the actual data is about 4M rows. I also don't care which record in the rightmost table is matched, as long as one or none is matched. Thanks!
table users:
-------------
| id | name |
-------------
| 1 | mike |
| 2 | john |
| 3 | bill |
-------------
table transactions:
---------------
| uid | spent |
---------------
| 1 | 5.00 |
| 1 | 5.00 |
| 2 | 5.00 |
| 3 | 5.00 |
| 3 | 10.00 |
---------------
expected output:
---------------------
| id | name | spent |
---------------------
| 1 | mike | 5.00 |
| 2 | john | 5.00 |
| 3 | bill | 5.00 |
---------------------
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…