CodingMySQL GROUP BY headspafe

 

Press Ctrl+Enter to quickly submit your post
Quick Reply  
 
 
  
 From:  Matt  
 To:  Peter (BOUGHTONP)     
30962.7 In reply to 30962.5 

Standard SQL I would have though.

 

The primary key requires the column to be unique so grouping on other columns becomes redudant because there is no duplicate data.

doohicky

0/0
 Reply   Quote More 

 From:  Peter (BOUGHTONP)  
 To:  Matt     
30962.8 In reply to 30962.7 
Makes sense.

But I often get errors at work when neglecting to add a fieldname to a group by bit... I guess it is possible that I only get them when not using the [whole] primary key. Which is probably more likely thinking about it - most group by stuff there is likely to be reports, when individual data isn't wanted, so would be grouping on less specific stuff.
Would be nice if there was a shortcut for 'everything except the function' though.
0/0
 Reply   Quote More 

 From:  Ben (BENLUMLEY)  
 To:  Matt     
30962.9 In reply to 30962.4 
presumably the optimiser in mysql will result in the queries being the same though?!
0/0
 Reply   Quote More 

 From:  Ally  
 To:  Peter (BOUGHTONP)     
30962.10 In reply to 30962.8 
The only time you should get an error is if you try and output anything that isn't SUMed, COUNTed, or GROUPed (or the other ones I forget)
0/0
 Reply   Quote More 

 From:  Matt  
 To:  Ben (BENLUMLEY)     
30962.11 In reply to 30962.9 

I was under the impression that the query optimiser rather than scan the query to know how to eliminate the unrequired modifiers, it simply reorgansied the query internally so it was more efficient in how it opened and closed tables and read from keys and such like.

 

After all without running the query multiple times it wouldn't know if the modifiers made a difference or not to the results would it?

doohicky

0/0
 Reply   Quote More 

 From:  Ben (BENLUMLEY)  
 To:  Matt     
30962.12 In reply to 30962.11 

i don't really know what it does and doesn't do ... just that it uses clevers to recognise queries that can be better performed differently, without actually trying the different versions.

 

I was under the impression that it did things like notice that one of the items in a group by is a unique index, so would ignore the rest?

 

No idea how i got this idea though, so its most probably wrong.

0/0
 Reply   Quote More 

Reply to All    
 

1–12

Rate my interest:

Adjust text size : Smaller 10 Larger

Beehive Forum 1.5.2 |  FAQ |  Docs |  Support |  Donate! ©2002 - 2024 Project Beehive Forum

Forum Stats