Jump to content

need help with mysql query


Roee

Recommended Posts

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.