Thread: Comparisons Sub-Select Issues

Comparisons Sub-Select Issues

From
"Brian C. Doyle"
Date:
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???



Re: Comparisons Sub-Select Issues

From
Jason Earl
Date:
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@mindspring.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/