Re: [SQL] subquery question

2009-03-12 Thread Bob Henkel
Does this help Here is my test table data. ID;DATE;VALUE 1;"2009-03-13";5 2;"2009-03-13";2 3;"2009-03-11";1 4;"2009-03-11";2 5;"2009-03-11";3 SELECT mydate AS day, SUM(CASE WHEN id % 2 = 1 THEN value END) AS sum_odd, SUM(CASE WHEN id % 2 = 0 THEN value END) AS sum_even FROM xyz GROUP

Re: [SQL] "Subquery must return only one column" & query optimization

2008-12-15 Thread Philippe Lang
pgsql-sql-ow...@postgresql.org wrote: > "Philippe Lang" writes: >> I was trying to run this query this morning: > >> -- >> SELECT > >> r.*, > >> ( >> SELECT > >> rl.reminder_header, >> rl.reminder_footer > >> FROM reminder_levels AS rl >> WHERE

Re: [SQL] "Subquery must return only one column" & query optimization

2008-12-15 Thread Tom Lane
"Philippe Lang" writes: > I was trying to run this query this morning: > -- > SELECT > r.*, > ( > SELECT > rl.reminder_header, > rl.reminder_footer > FROM reminder_levels AS rl > WHERE rl.lookup = > ( > SELECT MAX(rem

Re: [SQL] Subquery problems

2007-06-22 Thread Masaru Sugawara
> > Original Message > Subject: Re:[SQL] Subquery problems > From: Masaru Sugawara <[EMAIL PROTECTED]> > To: Ranieri Mazili <[EMAIL PROTECTED]> > Date: 21/6/2007 13:25 > > On Tue, 19 Jun 2007 09:17:22 -0300 > > Ranieri Mazili <[EMAIL PROTECTED]&g

Re: [SQL] Subquery problems

2007-06-21 Thread Masaru Sugawara
On Tue, 19 Jun 2007 09:17:22 -0300 Ranieri Mazili <[EMAIL PROTECTED]> wrote: Hi, This reply is not accurate, but I think there are helpful hints. -- Masaru Sugawara select C.id_production_area, B.id_machine_type, A.h_month as month, max(A.n) as div_mes, cast((sum(A.qty_employees_t

Re: [SQL] subquery abnormal behavior

2006-12-11 Thread Aaron Bono
On 12/11/06, Shoaib Mir <[EMAIL PROTECTED]> wrote: Oh that explains a lot... Thank you, - Shoaib Mir EnterpriseDB (www.enterprisedb.com) On 12/11/06, Michael Glaesemann <[EMAIL PROTECTED]> wrote: > > > On Dec 11, 2006, at 15:48 , Shoaib Mir wrote: > > > create table myt1 (a numeri

Re: [SQL] subquery abnormal behavior

2006-12-10 Thread Shoaib Mir
Oh that explains a lot... Thank you, - Shoaib Mir EnterpriseDB (www.enterprisedb.com) On 12/11/06, Michael Glaesemann <[EMAIL PROTECTED]> wrote: On Dec 11, 2006, at 15:48 , Shoaib Mir wrote: > create table myt1 (a numeric); > create table myt2 (b numeric); > > select a from myt1

Re: [SQL] subquery abnormal behavior

2006-12-10 Thread Michael Glaesemann
On Dec 11, 2006, at 15:48 , Shoaib Mir wrote: create table myt1 (a numeric); create table myt2 (b numeric); select a from myt1 where a in (select a from myt2); This should be giving an error that column 'a' does not exist in myt2 but it runs with any error... The a in the IN clause is the

Re: [SQL] subquery abnormal behavior

2006-12-10 Thread Shoaib Mir
I just noticed the same behavior in Oracle and SQL Server as well :) Regards, - Shoaib Mir EnterpriseDB (www.enterprisedb.com) On 12/11/06, Shoaib Mir <[EMAIL PROTECTED]> wrote: I just noticed an abnormal behavior for the subquery: create table myt1 (a numeric); create table myt2 (b n

Re: [SQL] subquery abnormal behavior

2006-12-10 Thread Rajesh Kumar Mallah
On 12/11/06, Shoaib Mir <[EMAIL PROTECTED]> wrote: I just noticed an abnormal behavior for the subquery: create table myt1 (a numeric); create table myt2 (b numeric); select a from myt1 where a in (select a from myt2); This should be giving an error that column 'a' does not exist in myt2 b

Re: [SQL] Subquery alternatives?

2006-09-05 Thread codeWarrior
I dont think you need the double-left join SELECT * FROM STORIES ST LEFT JOIN TAGS TG ON TG.tagkey = ST.storykey WHERE TG.tag = "science" "MRKisThatKid" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Hi, i've posted this in various places but I'm really struggling to > find

Re: [SQL] SubQuery

2001-10-03 Thread Stephan Szabo
On Thu, 4 Oct 2001 [EMAIL PROTECTED] wrote: > What mistake have I made? > > database1=# UPDATE mytable SET > NextNumber=NextNumber+1 > database1-# WHERE id='ID1' AND EffectiveDate= > database1-# (SELECT MAX(s2.EffectiveDate) FROM > mytable s2 > database1(# WHERE s2.id=id AND > s2.EffectiveDate<

Re: [SQL] Subquery with IN or EXISTS

2001-09-27 Thread A. Mannisto
Carl van Tast <[EMAIL PROTECTED]> wrote in message news:<[EMAIL PROTECTED]>... > Hi A., > > On 26 Sep 2001 07:24:41 -0700, [EMAIL PROTECTED] (A. Mannisto) > wrote: > > >Hello, > > > >does anybody know why this: > >SELECT * FROM tab WHERE col1 IN (SELECT col2 FROM TAB2) > > > >equals this: > >SE

Re: [SQL] Subquery with IN or EXISTS

2001-09-26 Thread Carl van Tast
Hi A., On 26 Sep 2001 07:24:41 -0700, [EMAIL PROTECTED] (A. Mannisto) wrote: >Hello, > >does anybody know why this: >SELECT * FROM tab WHERE col1 IN (SELECT col2 FROM TAB2) > >equals this: >SELECT * FROM tab WHERE EXISTS (SELECT col2 FROM TAB2 WHERE col1 = >col2) > >but this: >SELECT * FROM tab

Re: [SQL] Subquery error. Help please!!

2001-06-28 Thread Ross J. Reedstrom
I did something similar, but pu the subselect into a view, in the WHERE clause. SELECT * FROM modules m WHERE (m.module_ident = (SELECT max(modules.module_ident) AS max FROM modules WHERE (m.moduleid = modules.moduleid) GROUP BY modules.moduleid)); The equivalent for you would be something like:

Re: [SQL] Subquery error. Help please!!

2001-06-28 Thread Tom Lane
"kakerjak" <[EMAIL PROTECTED]> writes: > If the subquery is placed before the JOIN, like it is above, then the error > i get says 'parse error at or near "select"' > If i flip the subquery around with the laboratory table then i get 'parse > error at or near "("' Are you using 7.1?

Re: [SQL] Subquery error. Help please!!

2001-06-28 Thread Wei Weng
What version of postgresql are you using? On 27 Jun 2001 17:09:14 -0400, kakerjak wrote: > Hey all.. > > Here's the table definition. > CREATE TABLE "laboratory" ( > "id" "int4" NOT NULL, > "subid" "int2" NOT NULL, > "name" varchar(30) NOT NULL, > CONSTRAINT "laboratory_pkey" PRI