Friday, 15 April 2011

sql server - Joining the tables -



sql server - Joining the tables -

is there anyway in sql can like,

select table1.id, table2.admit, table2.value table2 bring together table1 on ids

if id in table1 not have value in admit column, create null (admit has either 1 or 0 in table2).

which means ids in table1.

here table output need:

id admit value 1256 0 advertisement 1254 1 na 1255 0 bk 1252 null null table1 id 1256 1254 1255 1252 table2 id admit value 1256 0 advertisement 1254 1 na 1255 0 bk 1257 1 ww

help appreciated. give thanks much.

this yield results asking for:

select t1.id, t2.admit, t2.value table1 t1 left outer bring together table2 t2 on t1.id = t2.id

here good article on few of different sql joins.

based on @nate's comment, here he's indicating:

select t1.id, isnull(t2.admit,0), isnull(t2.value,'-no entry-') table1 t1 left outer bring together table2 t2 on t1.id = t2.id

sql-server tsql

No comments:

Post a Comment