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
https://forums.phpfreaks.com/topic/168973-urgent-count-max-group-by/
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

 

  Quote

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

Archived

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

×
×
  • 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.