Last active
August 29, 2015 14:19
-
-
Save mohnish/a4259cdf60733224211e to your computer and use it in GitHub Desktop.
This file contains hidden or 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 b.name as bill, c.name as category, p.amount as amount, ps.name as card, ps.type as card_type | |
| FROM payments as p, bills as b, categories as c, payment_sources as ps | |
| WHERE b.user_id = 1 AND p.bill_id = b.id AND ps.id = p.payment_source_id AND c.id = b.category_id | |
| ; | |
| SELECT b.name as bill, c.name as category, p.amount as amount, ps.name as card, ps.type as card_type | |
| FROM bills as b | |
| INNER JOIN payments as p | |
| ON p.bill_id = b.id | |
| INNER JOIN categories as c | |
| ON c.id = b.category_id | |
| INNER JOIN payment_sources as ps | |
| ON ps.id = p.payment_source_id | |
| WHERE b.user_id = 1 | |
| ; |
Author
both are accurate. But, joins are faster than sub query and left join is faster than inner join
Author
i agree joins are faster. the first query gives you redundant results and is a slower query.
Query 1: "ps.user_id = b.user_id"
Query 2: "ON ps.id = p.payment_source_id"
both are different conditions baa
Author
you're right. let me update that first one.
Author
there you go
Now, both are accurate.
Author
you're right. and speed wise, both are similar.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
accuracy of results and performance