MySQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesMySQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old February 17th, 2005, 11:46 AM
BootyBean BootyBean is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2005
Posts: 1 BootyBean User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 34 m 38 sec
Reputation Power: 0
SQL query help needed

Hi. I'm trying to create a query but I'm not sure how to get what I'm looking for.

Here is a sample structure to what I'm using with just 2 tables. It is a database to record bird observations.

[observation] //one row per date surveyed; one to many relationship to [birdtally]
ID, site, Date

[birdtally] //row for each bird seen on this observation date
ID, bird, Total

I want to return a list of dates and 'total' for a specific site and specific bird so that I can chart that bird's numbers for each survey. So I used this query:

SELECT DISTINCT birdtally.Total, DATE_FORMAT(observation.Date,'%m/%d/%Y') as 'humandate'FROM birdtally LEFT JOIN observation ON observation.ID = birdtally.ID WHERE site='Lake Boogaloo' AND Bird='Bald Eagle' ORDER BY observation.Date

This returns close to what I want. The problem is that it only returns dates on which a Bald Eagle was seen. I need for it to return a row for every date surveyed, with a '0' for dates which no Bald Eagles were seen.

So if my sample database looked like this:

[observation]
1, Lake Boogaloo, 2000/1/1
2, Lake Boogaloo, 2000/1/2
3, Lake Boogaloo, 2000/1/3

[birdtally]
ID, bird, Total
1, American Coot, 4
1, Bald Eagle, 2
1, Common Raven, 3
2, Mallard, 4
2, Ruddy Duck, 3
3, Bald Eagle, 3
3, American Coot, 5

Then I want the result to be:

1/1/2000, 2
1/2/2000, 0
1/3/2000, 3

Reply With Quote
  #2  
Old February 28th, 2005, 03:52 AM
ijoxley ijoxley is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2005
Posts: 1 ijoxley User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 22 m 8 sec
Reputation Power: 0
Have you tried using a RIGHT JOIN instead of LEFT JOIN?

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesMySQL Development > SQL query help needed


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway