Jump to content

Problems retrieving values where count = 0


Buchead

Recommended Posts

Hello,

 

Been given a database that I'm trying to extract data from 3 of the fields. The ones in question are:

 

`bookings` - bookID, pitchID, gDate, gTime

`pitches` - pitchID,name,location

`pitch_tree` - pitchID, sectionID

 

The result needed is dependant upon the search criteria entered. If the end-user only searches on a pitch name it's easy, however they could search on a section (there are a few, each one a different sport and on a given date.  Each pitch has got 10 time slots throughout the day, so I need to return all the pitches that are in a certain section and either have no bookings or free slots on that date. If no bookings have been made then there will be no enteries in `booking`.

 

Built up the following query:

 

SELECT p.* FROM `pitches` AS p LEFT JOIN `bookings` AS b ON p.pitchID=b.pitchID LEFT JOIN `pitch_tree` AS t ON p.pitchID=t.pitchID
WHERE (b.gDate != '2007-11-05' OR COUNT(b.gDate) = 0) AND t.sectionID='2'

 

Clearly it doesn't work. Have tried grouping by gDate values and pitchID to no avail. Different joins and orders of the tables also has no effect.

 

Can someone please point out where I've messed up.

 

Thanks,

 

Clive.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.