using min|max in where - Mailing list pgsql-sql

From Ben Carbery
Subject using min|max in where
Date
Msg-id AANLkTinbg96cBzS+w31o75=wYUmHZxmwUJh4bKQc1Az2@mail.gmail.com
Whole thread Raw
Responses Re: using min|max in where  (Bruce Momjian <bruce@momjian.us>)
List pgsql-sql
Hi, I have some sql like so:<br /><br />SELECT min(date) INTO d FROM interest_rate WHERE m_code = NEW.code;<br />UPDATE
interest_rateSET date = NEW.start_date, rate = NEW.initial_rate WHERE m_code = NEW.code AND date = d;<br /><br />
Actuallythis is pgsql but I don't think that matters.<br /><br />I am wondering if I can make this more compact by
somehowincluding the 'min' function in the WHERE clause, but WITHOUT simply moving the select in there. So not
this..<br/><br />UPDATE interest_rate SET date = NEW.start_date, rate = NEW.initial_rate WHERE m_code = NEW.code AND
date= (SELECT min(date) FROM interest_rate WHERE m_code = NEW.code);<br /><br />This is just an example but I seem to
findthis pattern a lot in my functions.<br /><br />B<br /><br />        <br /> 

pgsql-sql by date:

Previous
From: Jann Röder
Date:
Subject: Re: Inefficient query plan
Next
From: Bruce Momjian
Date:
Subject: Re: using min|max in where