From: | john-paul delaney <jp(at)justatest(dot)com> |
---|---|
To: | pgsql-novice(at)postgresql(dot)org |
Subject: | Query combination query. |
Date: | 2005-02-22 11:20:38 |
Message-ID: | Pine.LNX.4.44.0502221203500.13362-100000@angelico.justatest.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-novice |
Hello List... Newbie question - is it possible to combine the following
two queries into one query statement returning, subject, created, topic_id, count?
thanks,
/j-p.
(Query1)
SELECT subject, created, topic_id FROM ap_forum_msg WHERE topic_seq = 1;
subject | created | topic_id
-----------------+-------------------------------+----------
A topic test 00 | 2005-02-22 09:14:25.444209+01 | 1
A topic test 01 | 2005-02-22 09:15:44.320408+01 | 2
(Query 2)
SELECT topic_id, count(topic_seq) FROM ap_forum_msg GROUP BY topic_id;
topic_id | count
----------+-------
1 | 2
2 | 3
(Table ap_forum_msg)
Column | Type | Modifiers
----------+--------------------------+---------------
topic_id | integer | not null
topic_seq | integer | not null
author_id | integer | not null
created | timestamp with time zone | default now()
subject | character varying(100) |
msg_text | character varying |
forum_id | integer | not null
Indexes: ap_forum_msg_pkey primary key btree (topic_id,
topic_seq)
Foreign Key constraints: $1 FOREIGN KEY (author_id) REFERENCES
apo_artist(apo_art_id) ON UPDATE NO ACTION ON DELETE NO ACTION,
$2 FOREIGN KEY (forum_id) REFERENCES
ap_forum(forum_id) ON UPDATE NO ACTION ON DELETE CASCADE
--
From | Date | Subject | |
---|---|---|---|
Next Message | Sean Davis | 2005-02-22 12:26:39 | Function with record type as argument |
Previous Message | Sean Davis | 2005-02-22 11:16:50 | Re: Query combination query. |