Link to home
Start Free TrialLog in
Avatar of Steve Tinsley
Steve TinsleyFlag for United Kingdom of Great Britain and Northern Ireland

asked on

SQL Count (with joins) Help

I am creating a simple booking system.. I wont to create 1 query which pull the GROUPS / OPTIONS & How may places left for each.

These are my tables.

user
User generated image
bookingGroup
User generated image
bookingOption
User generated image
user_bookingOption
User generated image
I want a query like below with one more column to this show how many bookings there has already been. That way I can minus bookingOptionAmount from how many there has already been to get how many is left

User generated image
SELECT *, bookingGroup.bookingGroupId, (
FROM bookingGroup
LEFT JOIN bookingOption ON (bookingGroup.bookingGroupId = bookingOption.bookingGroupId)

Open in new window



The query to get what i want is something think this.
SELECT count(user_bookingOption.userId) as placesTaken
FROM bookingOption
LEFT JOIN user_bookingOption ON (bookingOption.bookingOptionID = user_bookingOption.bookingOptionID)
WHERE bookingOption.bookingOptionId = bookingOption.bookingOptionId
GROUP BY(bookingOption.bookingOptionID)

Open in new window

Just want to combine it to the above query. Can I do this??

Steve
ASKER CERTIFIED SOLUTION
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Steve Tinsley

ASKER

GREAT HELP, THANKS!