Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2006-01-04 : 08:26:28
|
| sonal82 writes "I hv 2 tables table1 and table2 which have 2 common fields one is "tid" and second is "dayno". I want records from at least one of the tables i.e.table1:tid dayno 1 12 23 34 45 5table2:tid1 tid dayno city1 1 6 a2 1 1 b3 2 7 c4 5 2 d5 5 1 eI want records as:tid dayno city1 1 b2 2 Null3 3 Null4 4 Null5 5 Nulltid 3 and 4, are not in table2, but i want to display it, 2 and 5 are present but dayno is not matched hence city will be Null. plz help methanks in advance" |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2006-01-04 : 08:30:51
|
| Use Left joinSelect T1.tid, T1.dayno, T2.city from Table1 T1 left join Table2 T2 on T1.tid=T2.tid1MadhivananFailing to plan is Planning to fail |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2006-01-04 : 08:35:51
|
| [code]select t1.tid, t1.dayno, t2.cityfrom table1 t1 left join table2 t2 on t1.tid = t2.tid and t1.dayno = t2.dayno[/code]-----------------[KH]2006 a new beginning |
 |
|
|
|
|
|