Trying to merge a COUNT query in to an existing SELECT query
I'm stuck trying to merge a COUNT query in to an existing SELECT query
that I have.
Currently, I use this SELECT statement to fetch some contact info:
SELECT contact.id_contact, contact.cname, contact.cemail,
contact.trading_id, trading_name.trading_name
FROM contact
INNER JOIN trading_name ON contact.trading_id = trading_name.id_trading_name
WHERE (CHAR_LENGTH(contact.cname) > 0)
ORDER BY contact.cname
I also have this COUNT query which I need to somehow include in to the
same SELECT statement:
SELECT COUNT(AlertID) AS CustomerAlertCountTotal FROM
customer_support_dev.customer_alerts WHERE (AlertTradingID = @tradingid)
Basically I need to know how many 'AlertIDs' there are for each
'trading_name', and for that value to be returned in
'CustomerAlertCountTotal' - but by using just one query.
(If it makes a difference, I'm using a MySQL database)
Hope that makes sense :)
No comments:
Post a Comment