Preserving rows in SQL join

Post Reply
kevin31
Posts: 74
Joined: Fri Nov 01, 2002 12:45 pm

Preserving rows in SQL join

Post by kevin31 »

Suppose I have two tables like the following:

Table1
ID Name
1 Fred
2 Bob
3 Sue

Table 2
ID Initial
2 B

I would like to join these such that each row in Table1 is preserved and includes the Initial value from Table2 if it exists, i.e.
JoinTable
ID Name Inital
1 Fred NULL
2 Bob B
3 Sue NULL

Can I do this? What would the query be? Thanks!
kevin31
Posts: 74
Joined: Fri Nov 01, 2002 12:45 pm

Preserving rows in SQL join

Post by kevin31 »

Suppose I have two tables like the following:

Table1
ID Name
1 Fred
2 Bob
3 Sue

Table 2
ID Initial
2 B

I would like to join these such that each row in Table1 is preserved and includes the Initial value from Table2 if it exists, i.e.
JoinTable
ID Name Inital
1 Fred NULL
2 Bob B
3 Sue NULL

Can I do this? What would the query be? Thanks!
User avatar
mark
Site Admin
Posts: 5519
Joined: Tue Apr 25, 2000 6:56 pm

Preserving rows in SQL join

Post by mark »

Use nested SQL.
<sql row "select ... from table1">
<$Initial="">
<sql row "select .... from table2 where ID=$ID">
</sql>
</sql>
Post Reply