I'd like to modify the following query, so that instead of the ORDER.S_ID column, it fetches the value of the corresponding NAME column from the table (called STORES) S_ID refers to.
However, in some cases, S_ID is null, in which case there is no corresponding name column. In this case, there are still records from the ORDER and ORDERLIST tables that I want COUNT(*)-ed and thus displayed by the query, so that the result set's second column is null
SELECT
COUNT(*), ORDER.S_ID
FROM
ORDER, ORDERLIST
WHERE
ORDERLIST.O_ID = ORDER.ID AND
ORDER.DATE = '13-APR. -09 19.42.05,259000000'
GROUP BY S_ID;
sample data:
ORDER table
ID DATE S_ID
----------------------------------------
1 11-APR. -09 19.41.39,187000000 null
2 12-APR. -09 19.42.05,259000000 null
3 13-APR. -09 19.42.41,688000000 null
11 16-APR. -09 22.06.11,169000000 3
ORDERLIST table
O_ID B_ID PRICE
---------------------
3 6 7999
2 2 2000
2 6 7999
1 5 5000
1 1 1000
11 4 4000
11 6 7999
STORES table
ID NAME
----------
1 Store1
2 Store2
3 Store3
What I'd like to see returned if a user queries for a date where the S_ID value is NOT null: (this specific case is when queried the date 16-APR. -09 22.06.11,169000000 )
COUNT(*) STORENAME
2 Store3
What I want returned if it IS null: (querying for the date 13-APR. -09 19.42.41,688000000)
COUNT(*) STORENAME
1 null