I don't use SQL much these days, so my query writing skills have deteriorated... I've googled and looked around the net but haven't found a specific answer for my issue.
I have two tables, one that holds header information for sales orders, and the other that holds line information for those orders. They link through the order number. I am trying to write a query that will pull the order number for orders that have two specific items on them only.
The 'or' statement alone pulls all orders that have both items, as well as orders with just one or the other on them, and I want just the orders that have both. What I have so far:
select
header.ord_no,
line.item_no
from header
join line
on header.ord_no = line.ord_no
where line.item_no = 1
or line.item_no = 2
I know it's the 'or' statement that is the problem, but I'm not quite sure what the proper command is for this specific instance. Any help is greatly appreciated. Thanks.
I have two tables, one that holds header information for sales orders, and the other that holds line information for those orders. They link through the order number. I am trying to write a query that will pull the order number for orders that have two specific items on them only.
The 'or' statement alone pulls all orders that have both items, as well as orders with just one or the other on them, and I want just the orders that have both. What I have so far:
select
header.ord_no,
line.item_no
from header
join line
on header.ord_no = line.ord_no
where line.item_no = 1
or line.item_no = 2
I know it's the 'or' statement that is the problem, but I'm not quite sure what the proper command is for this specific instance. Any help is greatly appreciated. Thanks.