SQL INNER JOIN
Joining tables together usually means combining them based on a shared column called a foreign key.
Most of the time, the default join is an inner join. Here is a great explanation of the difference between left, right, inner, and outer joins.
select
tenants.name as tenant_name,
rent_payments.payment_date,
rent_payments.dollar_amount
from
rent_payments
inner join tenants on rent_payments.tenant_id = tenants.id;
tenants table
| id |
name |
| 1 |
Albert |
| 2 |
Marie |
| 3 |
Jose |
| 4 |
Terrell |
rent_payments table
| tenant_id |
building_id |
payment_date |
dollar_amount |
| 1 |
1 |
3/1/2018 |
2000 |
| 2 |
1 |
3/2/2018 |
1500 |
| 3 |
2 |
3/1/2018 |
1800 |
| 4 |
2 |
3/3/2018 |
1900 |
| 1 |
1 |
4/2/2018 |
2000 |
| 2 |
1 |
4/2/2018 |
1500 |
| 3 |
2 |
4/1/2018 |
1800 |
| 4 |
2 |
4/2/2018 |
1900 |
Query results
| tenant_name |
payment_date |
dollar_amount |
| Albert |
3/1/2018 |
2000 |
| Marie |
3/2/2018 |
1500 |
| Jose |
3/1/2018 |
1800 |
| Terrell |
3/3/2018 |
1900 |
| Albert |
4/2/2018 |
2000 |
| Marie |
4/2/2018 |
1500 |
| Jose |
4/1/2018 |
1800 |
| Terrell |
4/2/2018 |
1900 |