0

I am working on a small calendar application and practicing MySQL queries for finding available time slots based on the answer provided by flaschenpost

mysql show time slots avaliable and time slots busy from table

I am studying the query step by step. I ran the query below separately to see what it returns exactly.

(select 1 as place, 'Free' as name union select 2 as place, 'Booked' as name ) as d 
inner join bookingEvents b 

However, I got a syntax error:

ERROR 1064 (42000): You have an error in your SQL syntax;

I also tried the query below but still getting the same error.

   select (select 1 as place, 'Free' as name union select 2 as place, 'Booked' as name ) as d 

Please help.

Mint.K
  • 849
  • 1
  • 11
  • 27
  • please add a proper data sample and the expected result ... in you code there sintax and strcutural error ..and is not easy understand your goal – ScaisEdge Mar 06 '18 at 17:37
  • He has mentioned it from a different question which has such details. – stackFan Mar 06 '18 at 17:42
  • Your syntax is wrong. Follow the proper syntax. `SELECT ... FROM ... JOIN... WHERE...` – Eric Mar 06 '18 at 17:57

2 Answers2

3

Those are tables that belong in the from portion of your query.

Do this:

select 
    *
from
    (select 1 as place, 'Free' as name union select 2 as place, 'Booked' as name ) as d 
    inner join bookingEvents b 
RToyo
  • 2,877
  • 1
  • 15
  • 22
2

You are missing a from in the 2nd subquery so you are executing a select statement in none of the table.

On the 2nd query you have mentioned just put * from as

select * from (select 1 as place, 'Free' as name union select 2 as place,'Booked' as name ) as d 
stackFan
  • 1,528
  • 15
  • 22