Please see the SQL DDL below:
create table tablea (id int identity, name varchar(30))
create table tableb (id int identity, wid int, rid int)
create table tablec (id int)
insert into tablea(name) values ('ian')
insert into tableb(wid,rid)values (1,1)
insert into tablec values(1)
insert into tablec values(2)
insert into tablec values(3)
and the SQL statement below:
select tablea.* from tablea
left join tableb on tablea.id=tableb.wid
right join tablec on tablea.id=tablec.id
I wasn't sure what to expect with this. The results are:
2
3
I was expecting three results initially. Why are there two results? I realise this is a basic question, but I have not used SQL statements like this before.
The reason I expected three rows is because the following query returns one row:
select tablea.* from tablea
left join tableb on tablea.id=tableb.wid
and the following query returns two rows:
select tablea.* from tablea
right join tablec on tablea.id=tablec.id
and 2+1=3.