Reputation: 11861
I have two tables (table1 and table2) table1 has two columns day and timeSlot. table2 also has day and timeSlot columns. table1 has rows of date and times, table2 has rows of with inserted data including a date and time. My question is
I am trying to write a query string that will get me of list of dates not taken.
I have tried the following:
But it returns very random rows, in fact it will only take away one of the date and times taken.
SELECT table1.day, table1.timeSlot
FROM woodlandsBookingVipSalesDates
INNER JOIN table1 ON table1.day != table2.day AND table1.timeSlot != table2.timeSlot
My question is how do I get a list of day and timeSlot not taken.
Upvotes: 1
Views: 40
Reputation: 9398
your question is not very clear
I assume that woodlandsBookingVipSalesDates contains all used dates and time slots and that table_1 contains all the available dates and time slots
so I would simple do
SELECT table1.day, table1.timeSlot
FROM table_1 WHERE
(day, timeSlot) NOT IN (SELECT day, timeSlot FROM woodlandsBookingVipSalesDates )
Upvotes: 2
Reputation: 15071
Assuming you meant woodlandsBookingVipSalesDates
to be table1
and joining table2
...
Use NOT EXISTS
SELECT t1.day, t1.timeSlot
FROM table1 t1
WHERE NOT EXISTS (SELECT NULL
FROM table2 t2
WHERE t1.day != t2.day
AND t1.timeSlot != t2.timeSlot
)
Upvotes: 1