dbTalk Databases Forums  

Count question

comp.databases.mysql comp.databases.mysql


Discuss Count question in the comp.databases.mysql forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Some One
 
Posts: n/a

Default Count question - 04-07-2011 , 01:54 PM






Using MyISam. Assuming a simple table structure of Events with another
table of Event_Bands with 0-many bands associated with each row in Events.

I want to know the total count of bands associated with the event when a
specific band is associated with an event. I also need the data from the
row for the band in the where clause and want the result in a single row.

I got this working but I am wondering if there is an easier/faster way
to do this

select *,event_id as A, (select count(*) from event_bands group by
event_id where event_id = A) from event_bands where band_id=1

for example
Event 1 count should be 2

band id 1
band id 2

Event 2 count should be 1

band id 1

Event 3 (not selected)

band id 4

Thank you
Arn

Reply With Quote
  #2  
Old   
Some One
 
Posts: n/a

Default Re: Count question - 04-07-2011 , 02:08 PM






On or about 4/7/2011 2:54 PM, it came to pass that Some One wrote:
Quote:
Using MyISam. Assuming a simple table structure of Events with another
table of Event_Bands with 0-many bands associated with each row in Events.

I want to know the total count of bands associated with the event when a
specific band is associated with an event. I also need the data from the
row for the band in the where clause and want the result in a single row.

I got this working but I am wondering if there is an easier/faster way
to do this

select *,event_id as A, (select count(*) from event_bands group by
event_id where event_id = A) from event_bands where band_id=1

for example
Event 1 count should be 2

band id 1
band id 2

Event 2 count should be 1

band id 1

Event 3 (not selected)

band id 4

Thank you
Arn
Clarification
SQL should read
select *,event_id as A,(select count(*) from event_items where event_id
= A) from event_items where band_id=1

Reply With Quote
Reply




Thread Tools
Display Modes

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



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.