MYSQL QUERY - if another column is true in the query
Posted on 2016-09-05
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.