Performance with select query

  • I have a Select query something like this.

    Select a.emp,a.ename,b.dname,b.dept,e.loc,e.sid from emp a inner join dept  b on e.empid=d.deptid.

    This is just an example ..........in actual query we have lot of columns and lot of joins.My question is do we need to keep all columns froma table  then all columns from b table in select query?If we have select some columns from a table and some columns in b table and again some from a table.Is it going to effect performance?Any help is appreciated.

     

    Thanks,

    SR

     

     

    Thanks,
    SR

  • Not exactly sure of what you are asking but here's one answer.

     

    Performance wise you should always lessen the load of the server and network.  So return as little data as you can.  That means as lean data as possible (the smallest amount of columns) and the least amount how rows (don't do select * from table and then filter the data on the client side... works fine when there's a few hundred lines but in the 1000s that starts to slow down fast).

     

    Also the order in which you select the column in the statement doesn't affect anything.

     

    Does that answer your question?

  • Just to add to Ninja's response if u do select * then the columns that you join will appear more than once(once for every table that has those columns).

    Thanks

    Sreejith

  • Even if you just do Select * ...

    The key columns on which you join will be duplicates since a.id = b.id.  Only 1 of them needs to be returned.  Also assuming you do something like this :

    Select Col, Col2 from a inner join b on a.id = b.id where a.col2 = @Parameter

     

    then col2 should not be in the select statment because you already know its value (might be different in some reporting cases) .

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

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