Thursday, 15 May 2014

sql - Get an extra row with a join -



sql - Get an extra row with a join -

assume have next tables

chapters | id | title | --------------------- | 1 | introduction | lines | id | chapter | line | -------------------------------------- | 2 | 1 | fourscore , ... | | 5 | 1 | in beginning... |

what i'm looking in sql result following

| title | line | ----------------------------- | introduction | null | | introduction | fourscore | | introduction | in beg |

so want row title , other rows te matching lines. i've got 2 rows lines without missing null-line title.

any ideas?

try

select title,null line chapters union select title,line chapters bring together lines b on a.id=b.chapter

sql sql-server tsql

No comments:

Post a Comment