Created
November 23, 2022 21:07
-
-
Save parkerfoshay/7cd9d50dd43b0660a55185a24429e898 to your computer and use it in GitHub Desktop.
Joins
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
db.transfers.aggregate( [ | |
{ | |
$lookup: | |
{ | |
from: "accounts", | |
localField: "transfer_id", | |
foreignField: "transfers_complete", | |
pipeline: [ | |
{ $project: { _id: 0, account_id: 1, account_holder: 1 } } | |
], | |
as: "account_holder" | |
} | |
} | |
] ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT *, account_holder | |
FROM transfers | |
WHERE inventory_docs IN ( | |
SELECT account_holder, account_id | |
FROM accounts | |
WHERE transferss_complete = transfers.transfer_id | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment