sql server - SQL is it possible to use AND/OR with HAVING clause -
so have these tables:
products -------- product id | quantity and
orderslines ----------- product id | amount --(multiple lines same id) i'm using select:
select p.productid, p.quantity, sum(ol.amount) ordered atbl_sales_products p inner join atbl_sales_orderslines ol on ol.productid = p.productid group p.productid, p.quantity having p.quantity > sum(ol.amount) the select works if productid used in both tables. however, if productid not used in orderslines table or amount in table null - such rows not included.
when want join across tables need include records 1 side of join or other, need use 1 of outer joins opposed inner join in sql. if want include record atbl_sales_products when there may no matching record in atbl_sales_orderlines same productid should use left join.
as mentioned in comments can use operators use in where clause having clause.
Comments
Post a Comment