Q:

How the query works

Im with a doubt about a sql query because I'm not understanding properly how the join works so I don't understand properly how the q1 and q2 shows different results. Do you know how to translate one of the queries below explaining what is the sequence or steps of the query when there is a join?
Q1
select mems.firstname as memfname,
       mems.surname as memsname,
       recs.firstname as recfname,
       recs.surname as recsname
from cd.members mems
left outer join cd.members recs
on mems.memid = recs.recommendedby
order by memsname, memfname;   

Q2
select mems.firstname as memfname,
       mems.surname as memsname,
       recs.firstname as recfname,
       recs.surname as recsname
from cd.members mems
left outer join cd.members recs
on recs.memid = mems.recommendedby
order by memsname, memfname; 

A:

I don't understand properly how the q1 and q2 shows different results.

Well, the only difference here is the condition that applies for the left outer join.
// Q1: select ... and from mems and recs only where mems.memid is equal to recs.recommendedby
on mems.memid = recs.recommendedby

// Q2: select ... and from mems and recs only where recs.memid is equal to mems.recommendedby 
on recs.memid = mems.recommendedby

The left outer join just adds the entries from cd.members and recs to your result-set (select) based on the condition above.
Nothing too fancy happening here.
You can read more about this topic for example on:
https://en.wikipedia.org/wiki/Join_(SQL)

