Simple SQL help needed…

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bhanab
    New Member
    • Sep 2006
    • 7

    Simple SQL help needed…

    Please can you help me with syntax?

    I have two table t1 and t2,

    T1
    id Des
    1 Door
    2 Book

    T2
    Id Des
    1 CD
    1 phone
    2 office


    How do I get these results ?

    Id Des
    1 door
    1 CD
    1 phone
    2 book
    2 office
  • kestrel
    Recognized Expert Top Contributor
    • Jul 2006
    • 1071

    #2
    I have moved this to the forum.

    Comment

    • Vidhura
      New Member
      • May 2007
      • 99

      #3
      Originally posted by bhanab
      Please can you help me with syntax?

      I have two table t1 and t2,

      T1
      id Des
      1 Door
      2 Book

      T2
      Id Des
      1 CD
      1 phone
      2 office


      How do I get these results ?

      Id Des
      1 door
      1 CD
      1 phone
      2 book
      2 office
      Select * from T1
      union
      Select * from T2

      Comment

      • bhanab
        New Member
        • Sep 2006
        • 7

        #4
        Thanks for your reply...

        How about this error, ... how can I get this to work ?


        Declare @id int
        Set @id = '1'

        Select * from T1
        union
        Select * from t2
        Where T1.id = @id and T2.id = @id

        Msg 4104, Level 16, State 1, Line 4
        The multi-part identifier "T1.id" could not be bound.

        Comment

        • bhanab
          New Member
          • Sep 2006
          • 7

          #5
          Found it

          Declare @id int
          Set @id = '1'

          Select * from T1 where id = @id
          union
          Select * from t2 where id = @id

          Comment

          Working...