Re: Comparisons Sub-Select Issues

From: Jason Earl <jdearl(at)yahoo(dot)com>
To: "Brian C(dot) Doyle" <bcdoyle(at)mindspring(dot)com>, pgsql-general(at)postgresql(dot)org
Subject: Re: Comparisons Sub-Select Issues
Date: 2001-07-25 21:27:13
Message-ID: 20010725212713.28439.qmail@web10008.mail.yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

I do queries of this sort all of the time. If I used
the following script to create a couple of tables:

--BEGIN SQL script--
DROP TABLE birthdays;
DROP TABLE key_dates;

BEGIN;

CREATE TABLE birthdays (
username varchar(20) PRIMARY KEY,
dt date
);

INSERT INTO birthdays (username, dt) VALUES ('jason',
'1971-10-14');
INSERT INTO birthdays (username, dt) VALUES
('kaelynn', '1976-02-29');
INSERT INTO birthdays (username, dt) VALUES
('brooklyn', '1999-01-19');
INSERT INTO birthdays (username, dt) VALUES
('zachary', '2001-05-05');

CREATE TABLE key_dates (
name varchar(20) PRIMARY KEY,
dt date
);

INSERT INTO key_dates (name, dt) VALUES ('first date',
'1997-02-15');
INSERT INTO key_dates (name, dt) VALUES
('anniversary', '1997-05-10');
INSERT INTO key_dates (name, dt) VALUES ('Y2K',
'2000-01-01');

COMMIT;
--END SQL script--

I could then query the database like so:

processdata=> SELECT * FROM birthdays WHERE dt >=
(SELECT dt FROM key_dates WHERE name = 'first date');
username | dt
----------+------------
brooklyn | 1999-01-19
zachary | 2001-05-05
(2 rows)

In fact, this works with all kinds of values. If this
doesn't work for you then you have a serious problem
with your installation of PostgreSQL.

Or, more likely, I have simply misunderstood what your
problem is...

Hope this is helpful,
Jason

--- "Brian C. Doyle" <bcdoyle(at)mindspring(dot)com> wrote:
> Hello,
>
> How would I do a comparison sub select ie
> select this where that>=(*select something where
> whatever='exactly');
>
> Currently if I try to run a query in this format I
> get nothing back but if
> i remove the > I get an exact match which I do not
> want
>
> Can I do this???
>
>
>
> ---------------------------(end of
> broadcast)---------------------------
> TIP 6: Have you searched our list archives?
>
> http://www.postgresql.org/search.mpl

__________________________________________________
Do You Yahoo!?
Make international calls for as low as $.04/minute with Yahoo! Messenger
http://phonecard.yahoo.com/

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Joseph Shraibman 2001-07-25 21:38:06 postgres deadlocks
Previous Message Gregory Wood 2001-07-25 21:09:14 Hardware Recommendations