HAving Brain fade on a simple SQL query

  • Hi all,

    I'm having an issue remembering how to do this (simple) query in SQL.

    I have a view that pulls from about 5 tables, and I've created a duplicate view that pulls data from the same tables but for last year.

    I need to pull data from View1 and include 3 columns from view2.

    I've tried a union (which of course didn't work, Joining the tables (which gave me a lot more records that exist in either view)

    This was true of both inn, and left and right outer joins.

    Can some one help me?

    Thanks

    Craig

  • You need to join the views (union appends them together). You're getting duplicate rows because the join columns are either wrong or insufficient. What you have to join on I can't tell you, but it needs to be unique in one or both views if you don't want duplicate rows.

    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 2 posts - 1 through 1 (of 1 total)

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