Jump to content

Urgent! count max group by


kurbsdude

Recommended Posts

so here's the problem

 

I have a query as follows,

SELECT *, COUNT(*) FROM (SELECT x WHERE num = 1 UNION ALL SELECT num1 WHERE id = 4) AS id GROUP BY id

 

Is there a way to get MAX(COUNT(*)) without changing the "SELECT x WHERE num = 1 UNION ALL SELECT num1 WHERE id = 4" part?

 

Thanks in advance,

Cheers!!

Link to comment
Share on other sites

you query is well messed up dude.

 

do a count first

 

select count(*) as myCount FROM tablename WHERE afeild = (select afeild from another_table_or_same where afeild = 1)

 

this will return one row with mycount, you can group the counting proceedure group by feild that means it will only count the rows with feildname = thesame once

 

then get the records after

 

select * FROM tablename WHERE afeild = (select afeild from table where afeild = 1)

 

 

i dont think you can get a count and the records all in one

Link to comment
Share on other sites

 

this will return one row with mycount, you can group the counting proceedure group by feild that means it will only count the rows with feildname = thesame once

 

absolutely, I get one row as mycount but group by merges the counts right? I just want to get one maximum value from one group (not merge all)

 

thanks for the reply

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.