Re: help on SQL

From: Michael Stephenson <mstephenson(at)tirin(dot)openworld(dot)co(dot)uk>
To: Kenneth Suralta <ksuralta(at)ntsp(dot)nec(dot)co(dot)jp>
Cc: Gergely Czuczy <phoemix(at)harmless(dot)hu>, pgsql-interfaces(at)postgresql(dot)org
Subject: Re: help on SQL
Date: 2004-04-21 09:54:10
Message-ID: Pine.LNX.4.58.0404210952400.29792@tirin.openworld.co.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-interfaces

test=# create table data (data int);
CREATE
test=# insert into data values(1);
INSERT 3531768 1
test=# insert into data values(2);
INSERT 3531769 1
test=# insert into data values(3);
INSERT 3531770 1
test=# insert into data values(4);
INSERT 3531771 1
test=# insert into data values(5);
INSERT 3531772 1
test=# insert into data values(6);
INSERT 3531773 1
test=# insert into data values(7);
INSERT 3531774 1
test=# select * from data where (data - 1) % 3 = 0;
data
------
1
4
7
(3 rows)

test=#

HTH

Michael

Web Applications Developer
Open World Ltd, 11 Riverside Court, Riverside Road, Bath, BA2 3DZ.
Tel: +44 1225 444950 Fax: +44 1225 336738 http://www.openworld.co.uk/

CONFIDENTIALITY NOTICE
The information contained in this message is confidential, intended only for
the use of the individual or the entity named as recipient. If the reader of
this message is not that recipient, you are notified that any
dissemination,
distribution or copy of this message is strictly prohibited. If you have
received this message in error, please immediately notify us by telephone on
the number above. Your co-operation is appreciated.

On Wed, 21 Apr 2004, Kenneth Suralta wrote:

> hi gergely,
>
> thanks for replying..
> what i mean is supposing there is a table with the following rows:
>
> data
> -----
> 1
> 2
> 3
> 4
> 5
> 6
> 7
>
> is it possible to get every other N-row in the table?
> example, if N is 3.
> data
> -----
> 1
> 4
> 7
>
> thanks,
> kenneth
>
>
>
> Gergely Czuczy wrote:
>
> On Wed, 21 Apr 2004, Kenneth Suralta wrote:
>
>
>
> hello everyone,
>
> is it possible to get every other row in the table?
> like for example:
> data
> -----
> 1
> 2
> 3
> 4
> 5
> 6
> 7
>
>
> SELECT t.fields FROM table t WHERE data NOT IN (SELECT t2.data FROM table
> t2 WHERE some_whereclause);
>
> it will select these rows which ones are not in the subquery. but you can
> do it simply by getting the negate of the whereclause...
>
>
> Is it possible to have this result (interval of 3)?
>
> result
> ------
> 1
> 4
> 7
>
>
> i don't see what you mean. please describe it.
>
>
> thanks,
> kenneth
>
> --
>
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Don't 'kill -9' the postmaster
>
>
>
> Bye,
>
> Gergely Czuczy
> mailto: phoemix(at)harmless(dot)hu
> PGP: http://phoemix.harmless.hu/phoemix.pgp
>
> "Wish a god, a star, to believe in,
> With the realm of king of fantasy..."
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 2: you can get off all lists at once with the unregister command
> (send "unregister YourEmailAddressHere" to majordomo(at)postgresql(dot)org)
>
>
>
>
>
> --
> [IMAGE]
>
>

In response to

Responses

Browse pgsql-interfaces by date

  From Date Subject
Next Message Gergely Czuczy 2004-04-21 10:21:32 Re: help on SQL
Previous Message Kenneth Suralta 2004-04-21 07:50:07 Re: help on SQL