I'm building library which generates SQL queries and found case which i don't understand why it is happening so. I agree that in general you should filter out by "where" and not "on" yet ON allows to filter out for LEFT join. Though for RIGHT join i get results that do not match ON request. I wonder why RIGHT join works this way.
Users (table name _user
):
Invoices (table name _invoice
):
Query:
SELECT
_user.id AS userId,
_user.name AS userName,
_user.state AS userState,
_invoice.id AS invoiceId,
_invoice.userId AS invoiceUserId,
_invoice. `state` AS invoiceState
FROM
_user
RIGHT JOIN _invoice on _invoice.state = 'pending'
Response:
Question:
Would be best to get step-by-step execution for this query-result to understand how exactly it happen.