|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|
|
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
|
|||
|
|||
|
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 |
|
#2
|
|||
|
|||
|
Have you tried using a RIGHT JOIN instead of LEFT JOIN?
|
![]() |
| Viewing: Dev Articles Community Forums > Databases > MySQL Development > SQL query help needed |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|