mysql - Confusion in JOIN Query -


  select i.invoice_date inv,           i.invoice_id,           i.total_amount,           oi.invoice_date oi_inv,           oi.offline_invoice_number,           oi.invoice_amount      ci_invoices                left join ci_offline_invoice oi                          on oi.customer_id = 9     i.customer_id = 9  order i.invoice_date     limit 10 

this query give result

enter image description here

as see in screenshot have 1 row in highlighted section , want result according date:

2014-02-03 2014-01-16 2014-01-16 2014-01-16 2014-01-16 2014-01-16 .......... 

but got date 2014-02-03 every time(limit 10)

try this

select i.invoice_date inv,           i.invoice_id,           i.total_amount,           oi.invoice_date oi_inv,           oi.offline_invoice_number,           oi.invoice_amount      ci_invoices                left join ci_offline_invoice oi                          on oi.customer_id = i.customer_id    i.customer_id = 9  order i.invoice_date     limit 10 

** edit **

they not same thing.

consider these queries:

select i.invoice_date inv,           i.invoice_id,           i.total_amount,           oi.invoice_date oi_inv,           oi.offline_invoice_number,           oi.invoice_amount      ci_invoices                left join ci_offline_invoice oi                          on oi.customer_id = i.customer_id    i.customer_id = 9  order i.invoice_date     limit 10 

and

select i.invoice_date inv,           i.invoice_id,           i.total_amount,           oi.invoice_date oi_inv,           oi.offline_invoice_number,           oi.invoice_amount      ci_invoices                left join ci_offline_invoice oi                          on oi.customer_id = 9     i.customer_id = 9  order i.invoice_date     limit 10 

the first return ci_invoices , lines, if any, customer_id =9.

the second return ci_invoices, customer_id 9 have lines associated it.

on inner joins interchangeable, , optimizer rearrange them @ will.

on outer joins, not interchangeable, depending on side of join depend on.


Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -