Roee Posted July 15, 2010 Share Posted July 15, 2010 Hi, I've got complicated while trying to write the following mysq query. I hope you can help me to formulate it: I have a table which is called tbl1 and contains m_id, active, name Also I have another table which is called tbl2 and contains id, m_id I would like to find the rows from tbl2 which their m_id = m_id of the rows in tbl1, and in tbl1 these rows are active='0'. Moreover, I want to get the results with the less appearance, something like order by mysq_num_rows. How can I formulate this query? THANK YOU VERY MUCH ROEE Link to comment https://forums.phpfreaks.com/topic/207847-need-help-with-mysql-query/ Share on other sites More sharing options...
Maq Posted July 15, 2010 Share Posted July 15, 2010 Didn't test this, but it should give you an idea. Let me know if you have questions. SELECT t2.id, t2.m_id, COUNT(t2.m_id) AS c FROM tbl1 t1 LEFT JOIN tbl2 t2 ON t1.m_id = t2.m_id WHERE t1.active=0 GROUP BY t2.m_id ORDER BY c DESC; Link to comment https://forums.phpfreaks.com/topic/207847-need-help-with-mysql-query/#findComment-1086574 Share on other sites More sharing options...
Roee Posted July 15, 2010 Author Share Posted July 15, 2010 Thanks alot! Link to comment https://forums.phpfreaks.com/topic/207847-need-help-with-mysql-query/#findComment-1086677 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.