Q:

Query items that are not in the list, without having a unique id in one column

I'm looking to create a Python script that displays the items that are no longer available in the store (location 1) but are available in the warehouse (location 99). E.g. a list with items needed to be restocked. The difficulty is, that instead of putting the item count on 0 for the store, the inventory management system just removes the item completely from the database. Plus the fact that items don't have a unique ID, but are a combination of two columns being serial number and the column with the item's size.
The (PostgreSQL) database is restock with one table inventory looking like this:
====================================================================
| serialnumber  | size     | location     | itemcount   | season   |
--------------------------------------------------------------------
| 1120.10.0369  | 140      | 99           | 8           | 74       |
| 1120.10.0369  | 140      | 1            | 2           | 74       |
| 1120.10.4011  | 170/176  | 99           | 3           | 74       |
| 1120.10.4011  | 170/176  | 1            | 2           | 74       |
| 1120.10.4011  | 86/92    | 99           | 1           | 74       |
| 1120.10.8006  | 158      | 99           | 1           | 74       |
| 1120.10.8006  | 158      | 1            | 2           | 74       |

In the above example, the item with serial number 1120.10.4011 and size 86/92 is available in location 99 (the warehouse) but there is no row with serial number 1120.10.4011 and size 86/92 where location is 1, so that item I want to have on a list to be restocked.
I'm trying to show the items that don't exist in the data do this by using a count on a GROUP BY query:
getresult = "SELECT serialnumber, size, location, itemcount, season, COUNT(*)" + \
            "FROM inventory " + \
            "WHERE season = 74" + \
            "AND location != 1" + \
            "GROUP BY serialnumber, size " + \
            "HAVING COUNT(*) < 1"

However, this doesn't work as expected. 
The question still stands:

How can I retrieve a list with rows missing from the database? 

Or 

How can I retrieve a list with rows where the serialnumber + size are there for location 99 but are not present with a location of 1?

A:

You must use a subselect in a not exist clause:
getresult = """SELECT serialnumber, size FROM inventory i99
    WHERE season = 74 AND location = 99
    AND NOT EXISTS (SELECT serialnumber FROM inventory i1
        WHERE i1.serialnumber = i99.serialnumber
        AND i1.size = i99.size
        AND i1.location = 1)"""

That is the only way I know to find non existent values directly at the SQL level, because IS NULL even in an outer join test the value is the original table and not what will be returned by the select.

