Forum Moderators: coopster

Message Too Old, No Replies

Display last 3 records in a database column.

Display last 3 records in a database column.

         

knippysing

5:27 pm on Jul 21, 2005 (gmt 0)

10+ Year Member



I'm creating a call log or sorts and want to display the dates of the last 3 times they were called - pulled from the history log.

So basically, if customer=X then array the history, sort DESC and echo last 3 'dates'.

I have searched here and googled it but cannot seem to find it. Thanks as usual.

coopster

6:02 pm on Jul 21, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



MySQL or Postgresql? Either one has a LIMIT keyword you can use to retrieve only 3. Other databases have similar keywords ...

SELECT 
customer,
calldate
FROM customercalls
WHERE customer = 'X'
ORDER BY calldate DESC
LIMIT 3
;

knippysing

8:38 pm on Jul 21, 2005 (gmt 0)

10+ Year Member



Ok - I figured that out (I knew about it but did my query wrong in another part).

Anyway - my next task is difficult too. I am using 2 tables, webinquiries and call_log. I want to display all unique webinquiries where call_log.Status does not equal Call Back Later.
I have gotten that part with the following query:
SELECT * FROM webinquiries, call_log WHERE Date > $inquirydate AND call_log.CustomerStatus NOT LIKE 'Call Back Later';

My problem is, I need to select the LAST distinct line for each unique webinquiry. So I'm thinking there will be some sort of loop (while) statement or somesort but can't quite seem to figure it out.
Thanks