Selecting item list and count from other table
Hi, I have been failing at trying to get this query to work. Here is the query I can't get to work:
SELECT cont.key_no, (
SELECT COUNT(1)
FROM items itm
WHERE itm.cont_key_no = cont.key_no ) AS item_count
FROM containers cont
WHERE cont.status = 'OPEN';
Here is a query I managed to get working, but it doesn't quite do what I want it to. It doesn't return a container and item count for containers that don't have items:
SELECT cont.key_no, COUNT(itm.key_no) AS item_count
FROM containers cont, items itm
WHERE cont.status = 'OPEN'
AND itm.cont_key_no = cont.key_no
GROUP BY cont.key_no
Here are what the tables look like:
containers
----------
key_no
status
items
---------
key_no
cont_key_no
If you can't tell from the examples above, I am trying to return a list of all 'OPEN' containers and how many items are in the container, even if no items are in the container.
Subject
Written By
Posted
Selecting item list and count from other table
September 02, 2004 07:08PM
September 02, 2004 10:27PM
Sorry, you can't reply to this topic. It has been closed.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion
of Oracle or any other party.