troubleshooting Question

MYSQL QUERY - if another column is true in the query

Avatar of Steve Tinsley
Steve TinsleyFlag for United Kingdom of Great Britain and Northern Ireland asked on
9 Comments1 Solution84 ViewsLast Modified:
I have a query which pulls out data from a booking database.
It lists all the possible booking options as well and if the user has booked it.

The booking options have a topicID column, some options have the same topicID and cannot be booked twice.

I want to be able to add a column to my query which shows if the user has booked each topic... Perhaps by adding a topicBooked True/False column.

Current query example:
SELECT gb.* , bo.*, gb.bookingGroupId,
EXISTS ( SELECT * FROM user_bookingOption ubo WHERE bo.bookingOptionID =  ubo.bookingOptionID AND ubo.userId = 2112) as userHasBooked
FROM bookingGroup gb
LEFT JOIN bookingOption bo ON (gb.bookingGroupId = bo.bookingGroupId)

For each row I need to ask has there been an option booked with the same topic number in this query.

Any help would be much appreciated.
Join our community to see this answer!
Unlock 1 Answer and 9 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 9 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros