Jump to content

Archived

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

desithugg

join query count

Recommended Posts

[code]
$query = "SELECT forums.pic,forums.name,forums.des,forums.poster,forums.timer,forums.id,threads.fid FROM forums left join threads on threads.fid = forums.id  where category = 'general' ORDER BY ors ASC";
$result = mysql_query($query) or die(mysql_error());

[/code]

on the threads table i want to count how many threads are there that have the threads.fid = forums.id
do i use count i have tried count(threads.fid) and threads,count(fid) but didnt work. any other ideas?

Share this post


Link to post
Share on other sites
try
[code]$query = "SELECT forums.pic,forums.name,forums.des,forums.poster,
forums.timer,forums.id, COUNT(threads.fid) as threadcount
FROM forums left join threads on threads.fid = forums.id 
where category = 'general'
ORDER BY ors ASC";[/code]

Share this post


Link to post
Share on other sites
i ahve tried that barand but i get this error
Mixing of GROUP columns (MIN(),MAX(),COUNT(),...) with no GROUP columns is illegal if there is no GROUP BY clause

Share this post


Link to post
Share on other sites
Oops

[code]$query = "SELECT forums.pic,forums.name,forums.des,forums.poster,
forums.timer,forums.id, COUNT(threads.fid) as threadcount
FROM forums left join threads on threads.fid = forums.id 
where category = 'general'
GROUP BY forums.id
ORDER BY ors ASC";[/code]

Share this post


Link to post
Share on other sites

×

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.