UNION & JOIN

  • Hi

    what is the diff b/w UNION and JOIN .Please explain with examples

    Binu

  • Books online has good info on both. Or, if you don't have books online, the online technet library

    Join fundamentals: http://technet.microsoft.com/en-us/library/ms191517.aspx

    Union: http://technet.microsoft.com/en-us/library/ms180026.aspx

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • UNION - Combines the results of two or more queries into a single result set that includes all the rows that belong to all queries in the union. The UNION operation is different from using joins that combine columns from two tables.

    For eg:

    select_statement UNION [ALL] select_statement

    JOINS - By using joins, you can retrieve data from two or more tables based on logical relationships between the tables.

    For eg:

    select * from table1 A JOIN table2 B ON A.Some_ID=B.Some_ID

    SOURCE: BOL

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

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