Should the join be before or after where clause

  • SELECT adt_patient_master.pt_id, adt_patient_master.pt_lastname ,

    adt_visit_primary_master.pt_age, his_sex_m.sex_name FROM adt_patient_master, adt_visit_primary_master , his_sex_m ,

    WHERE adt_patient_master.pt_id = adt_visit_primary_master.pt_id

    AND adt_patient_master.pt_sex = his_sex_m.sex_id

    AND adt_patient_master.pt_id = '1016387'

    AND dt_visit_primary_master.visitid 'OP0001'

    On adt_patient_master table I have primary key clustered on the Field (pt_id)

    On adt_visit_primary_master table I have composite primary key clustered on Fields (pt_id, visitid)

    For better performance and sorting

    Should I have the join first in the where clause (WHERE adt_patient_master.pt_id = adt_visit_primary_master.pt_id)

    Or

    Should I have the pt_id in the where clause (where adt_patient_master.pt_id = '1016387')

    Mouli

    Edited by - Chandramouli on 12/19/2001 9:55:44 PM

    Edited by - Chandramouli on 12/19/2001 9:56:14 PM


    Mouli

  • Put your joins in the from clause - it wont many difference for performance, but it's ANSI and other developers will appreciate it.

    Andy

  • like

    select *

    from a

    inner join b

    on a.id = b.id

    inner join c

    on b.otherid = c.otherid

    and b.qty = c.qty

    Steve Jones

    steve@dkranch.net

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply