mysql - Inverse of Inner join (Intersect) with multiple foreign keys -


hi want opposite of intersect 2 tables.

i have sale table , purchase table. want purchases ids not included in sales table.

sale table

sale_id (pk)
product_id (fk)
purchase_id (fk)

purchase table

product_id (fk)
purchase_id (pk)

select distinct purchase_id               , product_id   purchase inner join sale using (purchase_id, product_id); 

here example: if run above code, result.

purchase_id   product id 1             1 1             2 1             4 2             1 2             3 

now want get:

purchase_id   product id 1             3 2             2 

in short want inverse of above code. in advance.

okay, think understand better now.

this should return entry in purchase have no matching entry in sales.

select     `purchase`.`purchase_id`, `purchase`.`product_id` `purchase`   left join `sale` on `sale`.`purchase_id` = `purchase`.`purchase_id` , `sale`.`product_id` = `purchase`.`product_id`    `sale`.`sale_id` null order    `purchase`.`purchase_id`, `purchase`.`product_id` 

Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -