sql server 2005 - return single row when 2 records in right table

Posted by Peanut on Stack Overflow See other posts from Stack Overflow or by Peanut
Published on 2010-05-06T06:26:35Z Indexed on 2010/05/06 6:38 UTC
Read the original article Hit count: 248

Filed under:
|

Hi, I have two related sql server tables ... TableA and TableB.

***TableA - Columns***
TableA_ID     INT
VALUE         VARCHAR(100)

***TableB - Columns***
TableB_ID     INT
TableA_ID     INT
VALUE         VARCHAR(100)

For every single record in TableA there are always 2 records in TableB. Therefore TableA has a one-to-many relationship with TableB.

How could I write a single sql statement to join these tables and return a single row for each row in TableA that includes:

  • a column for the VALUE column in the first related row in table B
  • a column for the VALUE column in the second related row in table B?

Thanks.

© Stack Overflow or respective owner

Related posts about sql-server-2005

Related posts about tables