0

please how to convert this query with inner join ?

(SELECT DISTINCT tables.table_id AS 'Available table ID'
   FROM tables, reservation 
  WHERE tables.table_id = reservation.table_id 
    AND ((start_time <> ? AND date = ?)
          OR (date <> ?)) 
          OR status = 1)
INTERSECT
(SELECT DISTINCT tables.table_id AS 'Available table ID'
   FROM tables, reservation 
  WHERE tables.table_id = reservation.table_id 
    AND ((start_time <> ? AND date = ?) 
          OR (date <> ? AND reservation.table_id <> ?))
          OR status=1)
JonK
  • 2,097
  • 2
  • 25
  • 36
  • 1
    This has nothing to do with Java. I've edited the question to remove the `Java` tag, but just a heads-up. – yshavit Apr 21 '14 at 22:48
  • Hopefully the query is a little more readable now – JonK Apr 21 '14 at 23:00
  • @Strawberry The question is tagged MySQL, which has no `INTERSECT` keyword. – Air Apr 21 '14 at 23:14
  • possible duplicate of [Alternative to Intersect in MySQL](http://stackoverflow.com/questions/2621382/alternative-to-intersect-in-mysql) – Air Apr 21 '14 at 23:14

1 Answers1

-1

You could try this: (I am not sure if you are looking for this answer)

(SELECT DISTINCT tables.table_id AS 'Available table ID'
   FROM tables JOIN reservation 
   ON (tables.table_id = reservation.table_id) 
   WHERE start_time <> ? AND date = ?
         OR (date <> ?)) 
         OR status = 1
INTERSECT
(SELECT DISTINCT tables.table_id AS 'Available table ID'
   FROM tables JOIN reservation 
   ON (tables.table_id = reservation.table_id) 
   WHERE start_time <> ? AND date = ? 
        OR date <> ? AND reservation.table_id <> ?)
        OR status=1