Jump to content

2 counts in one query? -


End User

Recommended Posts

I'd swear I've seen this done before but can't find any clear examples...Is there a way to get two counts from one query? For example, can I get a count of all rows in a table that belong to a given user_id, and at the same time get a count of all of those items that also have some other specific column value (like, "full member" or "banned" or whatever)?Never mind- solved:

SELECT (SELECT COUNT(*) FROM tableWHERE u_id= '1' ) AS total_ids, (SELECT COUNT(*) FROM tableWHERE u_level = 3) AS total_level

Link to comment
Share on other sites

Hi, i tried in a DB and i got the count, i'll try to translate to your SQLSELECT COUNT(*) AS total_ids, (SELECT COUNT(*) FROM table WHERE u_level = 3) AS total_level FROM tableWHERE u_id= '1'hope this help you.

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...