0

In relation to writing SQL queries, I could fetch something that I need in two ways:

Type 1:

select 
    cl.id 
from 
    datahub_clients             cl,
    datahub_client_accounts     cl_ac,
    datahub_accounts            ac    
where
    cl.id=cl_ac.client_id
    and
    ac.id=cl_ac.account_id
    and
    ac.account_no_dataphile="7H0010A1"
;

Type 2:

select 
    cl.id 
from 
    datahub_clients             cl
    join
    datahub_client_accounts     cl_ac
    on
    cl.id=cl_ac.client_id
    join
    datahub_accounts            ac    
    on
    ac.id=cl_ac.account_id
where
    ac.account_no_dataphile="7H0010A1"
;

Following are the few queries in my mind: 1) Is there any difference between how the SQL compiler interprets them? 2) Should there be preference around any one? (Why?) 3) From scalability perspective, which one is better?

1 Answers1

1
Type 2:

select 
    cl.id 
from 
    datahub_clients             cl
    join
    datahub_client_accounts     cl_ac
    on
    cl.id=cl_ac.client_id
    join
    datahub_accounts            ac    
    on
    ac.id=cl_ac.account_id
where
    ac.account_no_dataphile="7H0010A1"

is better because table name with comma separated create cross join( which is costly in terms of performance) between all those tables so it should be need to avoid

Type-1 is old method of join which strongly discourage to use

Zaynul Abadin Tuhin
  • 31,407
  • 5
  • 33
  • 63