Jump to content

Order or Max?


rarebit

Recommended Posts

Hi, I have this statement:

$s = "SELECT ".$tnF.".id, ".$tnF.".title, ".$tnF.".description, MAX(updated) AS updated, MAX(last_poster) AS last_poster , COUNT(*) AS num 
FROM ".$tnF." 
LEFT JOIN ".$tnT." ON forum_id = ".$tnF.".id 
WHERE cat_id = '".$e['id']."' 
GROUP BY ".$tnF.".id 
ORDER BY ".$tnF.".id ";

 

However the 'MAX(last_poster)' returns the name which is largest numerically, but I need it to be the name associated with the 'MAX(updated)' row.

 

Any ideas...

Link to comment
https://forums.phpfreaks.com/topic/115243-order-or-max/
Share on other sites

i've tried numerous ways to join them (there from the same table) but to no avail:

$s = "SELECT ".$tnF.".id, ".$tnF.".title, ".$tnF.".description, MAX(aa.updated) AS updated, bb.last_poster, COUNT(*) AS num 
FROM ".$tnF." 
INNER JOIN ".$tnT." AS aa ON ".$tnF.".id = aa.forum_id 
LEFT JOIN  ".$tnT." AS bb ON aa.updated = bb.last_poster 
WHERE cat_id = '".$e['id']."' 
GROUP BY ".$tnF.".id 
ORDER BY ".$tnF.".id ";

 

some form of example would help, i've gone through most of these...

 

Link to comment
https://forums.phpfreaks.com/topic/115243-order-or-max/#findComment-592731
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.