Received: from maia.hub.org (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id 6A330634DAE for ; Mon, 1 Feb 2010 04:16:22 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 26361-01-2 for ; Mon, 1 Feb 2010 08:16:11 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from n23.bullet.mail.mud.yahoo.com (n23.bullet.mail.mud.yahoo.com [68.142.206.162]) by mail.postgresql.org (Postfix) with SMTP id 6830A65A2B8 for ; Mon, 1 Feb 2010 03:36:58 -0400 (AST) Received: from [68.142.200.227] by n23.bullet.mail.mud.yahoo.com with NNFMP; 01 Feb 2010 07:36:56 -0000 Received: from [67.195.9.83] by t8.bullet.mud.yahoo.com with NNFMP; 01 Feb 2010 07:36:56 -0000 Received: from [98.137.27.220] by t3.bullet.mail.gq1.yahoo.com with NNFMP; 01 Feb 2010 07:36:56 -0000 Received: from [127.0.0.1] by omp130.mail.gq1.yahoo.com with NNFMP; 01 Feb 2010 07:36:56 -0000 X-Yahoo-Newman-Property: ymail-3 X-Yahoo-Newman-Id: 93165.54437.bm@omp130.mail.gq1.yahoo.com Received: (qmail 83909 invoked by uid 60001); 1 Feb 2010 07:36:56 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s1024; t=1265009815; bh=h8vkSBgQZ76n/MHvEatDF8ZLKLljmQmxgCWGdEEGYp0=; h=Message-ID:X-YMail-OSG:Received:X-Mailer:Date:From:Subject:To:MIME-Version:Content-Type; b=pwzfYzwBTgix4WNbW2ddJPg1oo/ULejwGcSeU0oV9vnzA3kWaoIHt+WvPE7gX0LmGK+52Mjnhyq8crtY/cBA0jnqF5aLYbTjy1S3uS3MY6AGR761vmohBySuQLQtrIpW0qkQi+m3E6Uqw68fCMz/VaeEhm+aUdv/IP/hqvAC9HI= DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=Message-ID:X-YMail-OSG:Received:X-Mailer:Date:From:Subject:To:MIME-Version:Content-Type; b=LF9yiv67Up5wB4Qn1lerPODkspHE3cArLY0axEtJsS8RwOOgZSjxFgbT5CXa76ZiSkeMqDyIrKrxSGggDAH0mtQlls0Puvw4ldEx0hBnC7UJg4QjYY5FHz37qDbW/bAnxwK1cbUgETgwXu0UXWPP8dEC1l5SQhOgcPzcP22aL+c=; Message-ID: <995516.81823.qm@web113717.mail.gq1.yahoo.com> X-YMail-OSG: NfOhG_MVM1neWsrPMYD_8YAaHQmfwjQgBPb8edPadQ9yL6Q1iMou8Gmz2_8JyG1X_DarLzkxkhDT2cUvHpblRRo6htV0Dsu_eq7WK9rwcdwViqzOycQWTMR93BtGEUTfk39jU_uCPpKRICFlb964Gmxx8yHxH6zFbTf9XGMSxbz3921HgaaKiGG3vCDV65WlLWNNfoLfUL.T4DAv80Ez_aSShl.uT25taAoJV4oT0GEApRRGlAUkzbum50ts7DDUYuCQjNZvaZT7HD_e3t9hT_lOaQ-- Received: from [173.22.34.57] by web113717.mail.gq1.yahoo.com via HTTP; Sun, 31 Jan 2010 23:36:55 PST X-Mailer: YahooMailClassic/9.1.10 YahooMailWebService/0.8.100.260964 Date: Sun, 31 Jan 2010 23:36:55 -0800 (PST) From: Neil Stlyz Subject: combine SQL SELECT statements into one To: pgsql-sql@postgresql.org, pgsql-novice@postgresql.org, pgsql-general@postgresql.org MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="0-866462374-1265009815=:81823" X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=2.811 tagged_above=-10 required=5 tests=BAYES_50=0.001, HTML_EXTRA_CLOSE=2.809, HTML_MESSAGE=0.001 X-Spam-Level: ** X-Archive-Number: 201002/5 X-Sequence-Number: 158781 --0-866462374-1265009815=:81823 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable Good Evening, Good Morning Wherever you are whenever you may be reading thi= s.=20 I am new to this email group and have some good experience with SQL and Pos= tgreSQL database. I am currently working on a PHP / PostgreSQL project and I came upon someth= ing I could not figure out in SQL. I was wondering if anyone here could tak= e a look and perhaps offer some guidance or assistance in helping me write = this SQL query.=20 Please Consider the following information:=20 ------------------------------------------- I have a postgresql table called 'inventory' that includes two fields: 'mod= el' which is a character varying field and 'modified' which is a timestamp = field.=20 So the table inventory looks something like this: =A0model=A0=A0=A0 =A0=A0=A0 =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0modified -------------=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 ---------- I778288176=A0=A0=A0=A0 =A0=A0=A0=A0=A0=A0 =A0=A0=A0 2010-02-01 08:27:00=20 I778288176=A0=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 2010-01-31 11:23:00 I778288176=A0=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 2010-01-29 10:46:00 JKLM112345=A0=A0=A0=A0=A0=A0=A0=A0=A0 =A0=A0=A0 2010-02-01 08:25:00 JKLM112345=A0=A0=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 2010-01-31 09:52:00 JKLM112345=A0=A0=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 2010-01-28 09:44:00 X22TUNM765=A0=A0=A0=A0=A0=A0=A0 =A0=A0=A0 2010-01-17 10:13:00 V8893456T6=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 =A0=A0=A0 2010-01-01 09:17:00 =A0 Now with the table, fields and data in mind look at the following three que= ries: =A0 SELECT COUNT(distinct model) FROM inventory WHERE modified >=3D '2010-02-01= '; SELECT COUNT(distinct model) FROM inventory WHERE modified >=3D '2010-01-20= '; SELECT COUNT(distinct model) FROM inventory WHERE modified >=3D '2010-01-01= '; =A0 All three of the above queries work and provide results. However, I want to= combine the three into one SQL Statement that hits the database one time. = How can I do this in one SQL Statement? Is it possible with sub select?=20 =A0 Here is what result I am looking for from one SELECT statement using the da= ta example from above: =A0 count1=A0|=A0 count2=A0 | count3 ------------------------------- =A02=A0=A0=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 2=A0=A0=A0=A0=A0 =A0=A0=A0 =A0=A0= =A0 4 Can this be done with ONE SQL STATEMENT? touching the database only ONE tim= e?=20 Please let me know.=20 =A0 Thanx> :) NEiL =A0=0A=0A=0A --0-866462374-1265009815=:81823 Content-Type: text/html; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable

Good Evening, Good Morning Wherever you are whenever you may be reading th= is.

I am new to this email group and have some good experience with= SQL and PostgreSQL database.

=
I am currently working on= a PHP / PostgreSQL project and I came upon something I could not figure ou= t in SQL. I was wondering if anyone here could take a look and perhaps offe= r some guidance or assistance in helping me write this SQL query.

= Please Consider the following= information:
-------------------------------------------
=

= I have a postgresql table cal= led 'inventory' that includes two fields: 'model' which is a character vary= ing field and 'modified' which is a timestamp field.

= So the table inventory looks = something like this:

=
 model  &n= bsp;             &nb= sp;         modified
------= -------              = ;  ----------
I778288176        =         2010-02-01 08:27:00
I778288176&nb= sp;              &nb= sp; 2010-01-31 11:23:00
I778288176       &= nbsp;         2010-01-29 10:46:00
JKLM1123= 45             = 2010-02-01 08:25:00
JKLM112345       &nbs= p;      2010-01-31 09:52:00
JKLM112345          &n= bsp;   2010-01-28 09:44:00
X22TUNM765    &= nbsp;       2010-01-17 10:13:00
V8893456T6 = ;              = 2010-01-01 09:17:00

=  

= Now with the table, fields an= d data in mind look at the following three queries:

=  

= SELECT COUNT(distinct model) = FROM inventory WHERE modified >=3D '2010-02-01';
SELECT COUNT(distinc= t model) FROM inventory WHERE modified >=3D '2010-01-20';
SELECT COUN= T(distinct model) FROM inventory WHERE modified >=3D '2010-01-01';

=  

= All three of the above querie= s work and provide results. However, I want to combine the three into one S= QL Statement that hits the database one time. How can I do this in one SQL = Statement? Is it possible with sub select?

=  

= Here is what result I am look= ing for from one SELECT statement using the data example from above:=

=  

= count1 |  count2&nb= sp; | count3
-------------------------------
 2   = ;           2   &nbs= p;          4

=
Can this be done with ONE= SQL STATEMENT? touching the database only ONE time?

= Please let me know.

=  

= Thanx> :)
NEiL

=  


=0A=0A --0-866462374-1265009815=:81823--