SQL Server Performance

I want to select the unique column names from 4 tables using the given query

Discussion in 'ALL SQL SERVER QUESTIONS' started by manshafmkd, May 26, 2012.

  1. manshafmkd New Member

    select * from t1 where exists(select * from t2 where t2.col1 = t1.col1 and t2.col2 = t1.col2)

    this code only the connection between two tables

    i want same code for connection between five tables

    Please give me a solution
  2. Shehap MVP, MCTS, MCITP SQL Server

    First Welcome to Forums,

    You could use joins commands by any logical type either Inner join or Full Outer join or Right outer or left Outer join ..etc such below example:

    select*fromt1innerjoint2ont2.col1=t1.col1andt2.col2=t1.col2

    innerjoint3ont3.col1=t1.col1andt3.col2=t1.col2

    innerjoint4ont4.col1=t1.col1andt4.col2=t1.col2

    innerjoint4ont5.col1=t1.col1andt5.col2=t1.col2

    but you have to look after join columns according to your business needs

    Please let me know if any further help needed
  3. Chililla New Member

    Joins are more usefull than the example above with a simple join you can merge all collums in a table for example

    select T1.ID, T1.Name, T1.etc, T2.id, T2.name, T2.etc from table_1 T1
    join Table2 T2 as T1.id = T2.id
    join Table3 T3 as T1.id = T3.id
    etc.
    with this all colums are joined and you can specify which colums do you need in the select statement
    note:
    the ID was just an example of a colum for a good join performance is more recomended to use PK values and one thing you have to have in mind is that the colims that you are joining have to match in deffinition by means is that you canĀ“t join collumns of different data types.

    Hope this can helps

Share This Page