mysql - SQL statement returns only rows that exist also in the joined table -
i cannot figure out how form proper sql statement this. want every row products table filter results if value in other table larger something.
my current statement returns every row want filter correctly unable make instead filter current result , print else
select p.* products p left join orders o on o.product_id = p.product_id , order_date < somedate o.id null
i want print whole products table except filter row if orders table column order_date smaller given date,
edit: helped me this!
you think complicated. want records table products order not exists. not exists in clause.
select * products not exists ( select * orders product_id = products.product_id , order_date < somedate );
(you can solve outer join, alwyays looks bit quirky in eyes. aware: when outer joining, don't use outer joined tables fields in clause, cause null outer joined record of course.)
Comments
Post a Comment