Go Back  HTML Forums - Free Webmaster Forums and Help Forums > WEBSITE DEVELOPMENT > Databasing
User Name:
Password:
 

Reply
Thread Tools   Display Modes
  View First Unread
 
Old 04-17-2009, 07:01 AM
  #1
welshsteve
Cue Master
 
welshsteve's Avatar
 
Join Date: Oct 2005
Location: Leamington Spa, UK
Posts: 2,444
iTrader: (0)
welshsteve is on a distinguished road
Help needed with using COUNT, GROUP BY and UNION together

Hi everyone, not sure if this is possible, but I have three tables with identical structures. They are lists of snooker breaks made in three different competitions. The table structures are:

Name
Club
Break

I want to do the following:

1. Sellect all records from the three tables
2. Count the number of rows for each player
3. Group the results by Player.

The end result would be:

Name................Club...............No. of breaks
Player 1.............Team 1.................10
Player 2.............Team 2..................9
Player 3.............Team 3..................8

etc etc

This is what I have, but it doesn't work

(SELECT Name, Club, COUNT(Break) AS Breaks FROM Breaks_Prem)
UNION
(SELECT Name, Club, COUNT(Break) AS Breaks FROM Breaks_A)
UNION
(SELECT Name, Club, COUNT(Break) AS Breaks FROM Breaks_Comp)
GROUP BY Name
ORDER BY Breaks DESC , Name , Club;


Is anybody able to help?
welshsteve is offline   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote
Old 04-18-2009, 05:06 AM
  #2
Vege
master of bloody obvious
 
Vege's Avatar
 
Join Date: Sep 2004
Location: Finland
Posts: 3,552
iTrader: (0)
Vege is just really niceVege is just really niceVege is just really niceVege is just really niceVege is just really nice
Quote:
SELECT Name,Club,COUNT(Break) as Breaks FROM ((SELECT * FROM Breaks_Prem) UNION
(SELECT * from Breaks_A) UNION
(SELECT * FROM Breaks_Comp)) as allali group by Name;
This works if your using mysql 5.0 or higher.
__________________
http://setala.info
Vege is offline   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote
Old 04-20-2009, 09:31 AM
  #3
welshsteve
Cue Master
 
welshsteve's Avatar
 
Join Date: Oct 2005
Location: Leamington Spa, UK
Posts: 2,444
iTrader: (0)
welshsteve is on a distinguished road
Hi, this doesn't quite work. Here's an example of what's happening.

Player 1 makes breaks of: 55, 46, 43, 41, 40, 38, 38, 36, 35, 33, 31, 31, 31, 30, 30

That's 15 breaks. But the count is returning 13 breaks
welshsteve is offline   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote
Old 04-25-2009, 08:36 AM
  #4
Vege
master of bloody obvious
 
Vege's Avatar
 
Join Date: Sep 2004
Location: Finland
Posts: 3,552
iTrader: (0)
Vege is just really niceVege is just really niceVege is just really niceVege is just really niceVege is just really nice
Quote:
Originally Posted by welshsteve View Post
Hi, this doesn't quite work. Here's an example of what's happening.

Player 1 makes breaks of: 55, 46, 43, 41, 40, 38, 38, 36, 35, 33, 31, 31, 31, 30, 30

That's 15 breaks. But the count is returning 13 breaks
I'w been away for a while and i apologize that i haven't been able to ansver.

Sorry but i don't see an error in my query. Can you post the sql to produce working example of my query not working
__________________
http://setala.info
Vege is offline   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote

Reply
KEEP TABS
SPONSORS
 
Boxedart



 
 


 
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
  
 
 
 



 
  POSTING RULES
 
 
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Thread Tools
Display Modes

Forum Jump

 

All times are GMT -5. The time now is 10:37 AM.

   

Mascot team created by Drawshop.com

Powered by vBulletin® Version 3.6.7
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.

Server Monitoring by ENIACmonitor 0.01
HTMLforums.com © Big Resources, Inc. Web Design by BoxedArt.com
vRewrite 1.5 beta SEOed URLs completed by Tech Help Forum and Chalo Na.