sql - Performance impact due to Join -
i have 2 tables product , account.
product table columns
product_id (pk) subscription_id
account table columns
account_nbr subscription_id (account_nbr , subscription_id primary key columns in account table) ... other columns
i have find account_nbr
, subscription_id
product_id
.
i product_id
input. using can subscription_id product table
, using subscription_id
can account_nbr
value account table.
instead of getting info in 2 queries, can done in 1 query?
something below:
select distinct a.acct_nbr,p.subscription_id account a,product p v.product_id = ' val 1' , v.subscription_id = p.subscription_id
will performance of above query low compared 2 separate queries?
i have find account_nbr , subscription_id product_id.
so, you're correct in approach need join 2 result-sets together:
select p.account_nbr, p.subscription_id account join product p on a.subscription_id = p.subscription_id p.product_id = :something
some points:
- you have alias
v
in query; don't know came from. - learn use ansi join syntax; if make mistake it's lot more obvious.
- you're selecting
a.acct_nbr
, doesn't exist as-is. - there's no need distinct. account_nbr , product_id primary key of account.
will performance of above query low compared 2 separate queries?
probably not. if query correct , tables correctly indexed it's highly unlikely whatever you've coded beat sql engine. database designed select data quickly.
Comments
Post a Comment