I have an HTML table that is generated from a query of the 'user' table that finds all users on a system.
A second query uses 'select count' to count how many meetings a user has booked by checking how many times their userID appears in the meetings table.
<cfquery datasource="iPad" name="Two">
SELECT COUNT(userID) AS meetingsCount from meeting where userID = '#One.userID#'
</cfquery>
I would like to be able to reorder the table based on the meetingsCount by clicking a link on the page. The problem is I'm not sure how to query this information as it doesn't technically exist on the table in MYSQL.
Edit; code using left join and validation.
select user.userID, user.contactName, user.email, count(meeting.userID)
as meetingsCount
from user where user.userID = 30
AND user.userID NOT IN ('1', '2', '3', '4', '58', '59', '62',
'63', '64', '66', '69', '71', '72', '73', '78', '107')
AND SUBSTRING( meeting.meetingCode, 5, 2 )
BETWEEN 12 AND 22
AND SUBSTRING( meeting.meetingCode, 7, 2 )
BETWEEN 1 AND 12
AND SUBSTRING( meeting.meetingCode, 9, 2 )
BETWEEN 01 AND 31
left outer join meeting on user.userID = meeting.userID