Which of these queries is preferable?
Posted
by bread
on Stack Overflow
See other posts from Stack Overflow
or by bread
Published on 2010-06-09T08:36:49Z
Indexed on
2010/06/09
8:42 UTC
Read the original article
Hit count: 217
sql
I've written the same query as a subquery and a self-join.
Is there any obvious argument for one over the other here?
SUBQUERY:
SELECT prod_id, prod_name
FROM products
WHERE vend_id = (SELECT vend_id
FROM products
WHERE prod_id = ‘DTNTR’);
SELF-JOIN:
SELECT p1.prod_id, p1.prod_name
FROM products p1, products p2
WHERE p1.vend_id = p2.vend_id
AND p2.prod_id = ‘DTNTR’;
© Stack Overflow or respective owner