MySQL Forums
Forum List  »  PHP

query within query
Posted by: David White
Date: April 06, 2006 03:06PM

Hi fellow Martians

I have two tables STATs (statistics) and SITEs (websites).
The first STATs contains a series of records that are in date order, the second SITEs the list of websites.

I want to list the sites with the oldest stats first.

The following works badly in that at least it shows the last date that STATs were added for each site but in the wrong site order:

select
cp_SITEs.site_id,
cp_SITEs.site_name, cp_SITEs.URL,
cp_STATs.gpages,cp_STATs.glinks,
cp_STATs.ypages, cp_STATs.ylinks,
cp_STATs.mpages, cp_STATs.mlinks,
DATE_FORMAT(cp_STATs.date,'%d %M %Y') as statdate

from
cp_SITEs, cp_STATs

where
cp_SITEs.current=0 and cp_SITEs.parent_id=$account_id
and
cp_SITEs.URL != ''
and
cp_SITEs.site_id= cp_STATs.site_id

order by
cp_STATs.site_id asc, cp_STATs.date desc


It seems the more I stare the less I can see!

Replies appreciated.

David

Options: ReplyQuote


Subject
Written By
Posted
query within query
April 06, 2006 03:06PM
April 06, 2006 04:28PM
April 06, 2006 05:47PM
April 06, 2006 05:58PM
April 06, 2006 09:36PM
April 07, 2006 04:48PM
April 07, 2006 06:15PM
April 07, 2006 09:23PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.