question

cstephen avatar image
cstephen asked

I have 3 tables and I have to right outer join Table A with Table B but a left outer between Table A and Table C. Can I combine outer and inner join in the same query?

Suppose i am having three tables a and b,c and like to join c to a in the right outer-join here i just mentioned the query which was modified by me..The logic of this join is good or not? Or It is good practice for Joining the table under this condition select convert(char(10),gr_del_actrecdate,120) 'ACTUALRECEIPTDATEML', ltrim(rtrim(gr_del_delaybydays)) 'DELAYATTOTSUPP', ltrim(rtrim(gr_del_delayatrbto)) 'DELAYATTTO', gr_del_delaydays 'DELAYINDAYS', gr_del_delno 'LINENO_HIDN', convert(char(10),gr_lin_schdate,120) 'EXPECTEDDELYDATEML', gr_lin_orderschqty 'EXPECTEDQTYML', ltrim(rtrim(paramdesc)) 'LINESTATUS', gr_lin_orderqty 'ORDERQTYML', gr_lin_grlineno 'RECEIPTLINENOML', gr_del_recqty 'RECEIVEDQTY', ltrim(rtrim(gr_del_shortatrbto)) 'SHORTAGEATTTO', ltrim(rtrim(gr_del_shortbyqty)) 'SHORTAGEATTTOSUPP', gr_del_shortqty 'SHORTAGEQTYML' from gr_del_delivery right outer join ( gr_hdr_grmain inner join gr_lin_details on( gr_lin_ouinstid = gr_hdr_ouinstid and gr_lin_grno = gr_hdr_grno and gr_hdr_ouinstid = '31' and gr_hdr_grno = 'tvtgr/000007/1011' )) on (gr_del_ouinstid = gr_hdr_ouinstid and gr_del_grno = gr_hdr_grno and gr_del_grlineno = gr_lin_grlineno ), component_metadata_table where componentname = 'GR' and paramcategory = 'META' and paramtype = 'LINE_STATUS' and paramcode = gr_lin_linestatus and langid = '1' order by gr_lin_grlineno
t-sqljoins
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Grant Fritchey avatar image
Grant Fritchey answered
The only way to know if the performance is good or not is to measure the time it takes for the query to run and observe the number of reads that running the query causes. These are your best measures of performance. For the time, you need to run it 3-4 times to get an average value because a single run won't necessarily reflect reality since it will include the time to compile the plan and load the information off the disk and into the cache. Use SET STATISTICS IO ON and SET STATISTICS TIME ON to get the measurements you want. To understand what's occurring within the query, use the execution plan, just understand that is not a method for measuring performance.
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.