Skip site navigation (1) Skip section navigation (2)

Select and order by question

From: Andy Dunlop <andy(at)infocus(dot)co(dot)za>
To: pgsql-php(at)postgresql(dot)org
Subject: Select and order by question
Date: 2006-05-03 09:13:10
Message-ID: 1146647591.7286.284.camel@localhost.localdomain (view raw, whole thread or download thread mbox)
Lists: pgsql-php
Hi - I have the following code:

//show table of current events needing action
$sSql = "SELECT id FROM crm_leads ";
$sLeads = pg_exec($conn,$sSql);
        $sSql = "SELECT * FROM crm_events WHERE crm_leads_id =
".pg_result($sLeads,$e,"id")." AND follow_up_action!='' ORDER BY
follow_up_date asc limit 1";
        $sRes = pg_exec($conn,$sSql);
        $sHits = pg_numrows($sRes);
              // generate the display here

crm_leads is a parent with many crm_events as it's children.
This code gives me the correct set of rows.
My problem is that I want only the last row from crm_events (as per
limit 1) but I want those rows sorted by follow_up_date. I guess I need
to have the whole query in one select statement? But how? 

Any help appreciated
Andy Dunlop
+27 21 532 0335 office
+27 82 770 8749 mobile


pgsql-php by date

Next:From: kmh496Date: 2006-05-03 09:14:45
Subject: Re: server dropping connection
Previous:From: Reed LoefgrenDate: 2006-05-03 00:13:57
Subject: server dropping connection

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group