Jump to content

Recommended Posts

Hi, I have the following code:

 

SELECT *, count(a.id) as number FROM a, b, c WHERE a.id = b.userid AND a.type = b.type AND b.status = 'Enable' AND c.same_type = a.type AND c.threshold >= (SELECT *, count(a.id) as numbers FROM a, b WHERE a.id = b.userid AND a.type = b.type AND b.status = 'Enable') ORDER BY number ASC

 

Everything works fine but when i add:

(SELECT c.threshold FROM c WHERE c.same_type <= a.type)

 

It doesn't make a difference if i use the less than or greater than. If i add a number instead of the full statement then it works fine. I need to be able to get the number from the database. It would be easier if i could add the counted "number" instead of the second sql statement

 

 

Link to comment
https://forums.phpfreaks.com/topic/244963-mysql-statement-not-working-properly/
Share on other sites

Yes i realised that when i added more different rows to the table and it wasn't giving me the corrct result. I then used GROUP BY and works perfectly. Thanks for your help, it's tough when your brain goes thru too many different solutions.

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.