I am currently working on a database which stores information which allows users to make reservations at a restaurant.
I am trying create a SQL statement which returns the times which appear less than twice in the reservations table.
At the moment I have this but this only returns the times which do not appear in the reservations table at all.
SELECT *
FROM TIME
WHERE
TIME NOT IN (
SELECT reservation.a_time
FROM
RESERVATION
JOIN TIME ON
reservation.a_time = time.time
WHERE
reservation.a_date = :the_date
)
ORDER BY time;
The above statement returns all times which are not in the reservations table. However how would I return all times which appear in the reservations table including those that appear once but not those that appear twice?
Thanks
or
I prefer the first, because it is cleaner, more clear and can be expanded easier, despite the subselect.