Re: SQL Subquery on Max(date)
- From: Bob Hairgrove <invalid@xxxxxxxxxxx>
- Date: Mon, 23 Apr 2007 06:44:11 +0200
On Sun, 22 Apr 2007 16:00:08 +0200, Bob Hairgrove <invalid@xxxxxxxxxxx> wrote:
CREATE TABLE oncd_activity_company (
company_id LONG NOT NULL,
activity_id LONG NOT NULL,
due_date DATETIME NOT NULL,
CONSTRAINT pk_oncd_activity_company
PRIMARY KEY (company_id, activity_id),
CONSTRAINT fk_company
FOREIGN KEY (company_id)
REFERENCES oncd_company (company_id),
CONSTRAINT fk_activity
FOREIGN KEY (activity_id)
REFERENCES oncd_activity (activity_id)
);
Actually, all three columns should go into the composite primary key here:
...
CONSTRAINT pk_oncd_activity_company
PRIMARY KEY (company_id, activity_id, due_date),
...
etc. Otherwise, it doesn't make sense to do the GROUP BY on company_id and
activity_id.
--
Bob Hairgrove
NoSpamPlease@xxxxxxxx
.
- References:
- SQL Subquery on Max(date)
- From: chollstein
- Re: SQL Subquery on Max(date)
- From: Bob Hairgrove
- SQL Subquery on Max(date)
- Prev by Date: Re: Problem with Select INTO
- Next by Date: Re: MSACCESS.EXE Hangs in Memory - NEED HELP!
- Previous by thread: Re: SQL Subquery on Max(date)
- Next by thread: Re: Using Web Services
- Index(es):
Relevant Pages
|