JOINING OF TWO TABLES

  • HI

    i have two tables with different number of rows and no identity columns in each one

    i want to join them and retrieve in single table

    please help me

  • You can use UNION to combine queries.

    ex.

    SELECT Name, City FROM Suppliers

    WHERE Country = 'Mexico'

    UNION SELECT Name, City FROM Customers

    WHERE Country = 'Mexico'

  • Create View v1

    as

    Select Eno,Ename from e1.dbo.emp

    where Eno = 5

    Union All

    Select Eno,Ename from e1.dbo.empmast

    where Eno = 5

    Now,

    Select Eno,Ename from v1

    karthik

  • VENUGOPAL.RR (7/30/2008)


    HI

    i have two tables with different number of rows and no identity columns in each one

    i want to join them and retrieve in single table

    please help me

    How many rows are in each table? How many rows are you expecting in the output? What are the table structures? Identity columns are not essential for joining tables.

    There's very little information to work with; you won't get an answer straight away, instead you will get a barrage of questions until enough is known about your problem. The following link provides guidelines on how to post a question to get an answer quickly:

    http://www.sqlservercentral.com/articles/Best+Practices/61537/

    Cheers

    ChrisM

    “Write the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.” - Gail Shaw

    For fast, accurate and documented assistance in answering your questions, please read this article.
    Understanding and using APPLY, (I) and (II) Paul White
    Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden

  • karthikeyan (7/30/2008)


    Create View v1

    as

    Select Eno,Ename from e1.dbo.emp

    where Eno = 5

    Union All

    Select Eno,Ename from e1.dbo.empmast

    where Eno = 5

    Now,

    Select Eno,Ename from v1

    Karthik, why not just join the two tables on Eno? 😉

    “Write the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.” - Gail Shaw

    For fast, accurate and documented assistance in answering your questions, please read this article.
    Understanding and using APPLY, (I) and (II) Paul White
    Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden

  • Karthik, why not just join the two tables on Eno?

    Chris,

    I do agree with you. We can use Join also.:D

    karthik

  • i have two tables more than 10,000 rows in each table

    each from different databases

    and also having different number of rows

    i want just marely join those tables and render in a single table

    i want just as outter join

    not cross join

  • Not enough information. Please post your table structure and give us an idea what the data looks like and what you want returned.

    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

Viewing 8 posts - 1 through 7 (of 7 total)

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