how to generate the result using mssql command

Discussion in 'Databases' started by alanX, Aug 14, 2007.

  1. #1
    table 1:
    column1
    1
    2
    3
    4
    5
    6


    table 2
    column1 column2
    1 ----------- a
    3 ----------- b
    5 ----------- c

    expected result:

    column1 column2
    1 ------------ a
    2 ------------ a
    3 ------------ b
    4 ------------ b
    5 ------------ c
    6 ------------ c

    how to write the SQL command so as to generate the expected result

    (p.s atually there are many rows in table 1 ana table2)
     
    alanX, Aug 14, 2007 IP
  2. supperman

    supperman Peon

    Messages:
    22
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    can you give more clue?
    i think it should use a inner join,but i can't write

    if possible,can you upload a sql file,so that I can try fix?

    I met the problem before

    /s
     
    supperman, Aug 17, 2007 IP
  3. Clark Kent

    Clark Kent Guest

    Messages:
    122
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Try this:

    select t1.column1, t2.column2
    from table1 t1
    inner join table2 t2 on t2.column1=t1.column1
     
    Clark Kent, Aug 17, 2007 IP
  4. tamilsoft

    tamilsoft Banned

    Messages:
    1,155
    Likes Received:
    78
    Best Answers:
    0
    Trophy Points:
    0
    #4
    SELECT T1.column1,T2.column2 FROM table1 T1,table2 T2 WHERE T1.column1=T2.column1
    PHP:
     
    tamilsoft, Aug 20, 2007 IP