Re: [SQL] JOIN query not working as expected

2005-12-06 Thread Tom Lane
Mario Splivalo <[EMAIL PROTECTED]> writes: > I can create a FK on a column wich allows NULL values, and I can even > insert rows with NULLs in FK column, although PK table where FK is > pointing does not allow nuls. Is that 'by design', or...? It's per SQL spec. Add a NOT NULL constraint to the c

Re: [SQL] JOIN query not working as expected

2005-12-06 Thread Mario Splivalo
On Tue, 2005-12-06 at 09:58 -0500, Tom Lane wrote: > Mario Splivalo <[EMAIL PROTECTED]> writes: > > Now I want all services which didn't have any messages within certain > > period: > > pulitzer2=# select * from services where id not in (select distinct > > service_id from messages where receiving_

Re: [SQL] JOIN query not working as expected

2005-12-06 Thread Tom Lane
Mario Splivalo <[EMAIL PROTECTED]> writes: > Now I want all services which didn't have any messages within certain > period: > pulitzer2=# select * from services where id not in (select distinct > service_id from messages where receiving_time between '2005-10-01' and > '2005-10-30'); > (0 rows) >

[SQL] JOIN query not working as expected

2005-12-06 Thread Mario Splivalo
How is this possible? I have two tables. 'services', and 'messages'. Each message can be assigned to one service, or it can be unnasigned. Therefore 'service_id' column in table 'messages' is not foreign-keyed to 'id' column in services table. services.id is PK for services, messages.id is PK for