MySQL INNER JOIN和SELECT

问题描述 投票:0回答:2

我正在开发一个小型日历应用程序,并根据flaschenpost提供的答案练习MySQL查询以查找可用的时间段

mysql show time slots avaliable and time slots busy from table

我正在逐步研究查询。我单独运行下面的查询,看看它究竟返回了什么。

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

但是,我遇到了语法错误:

错误1064(42000):您的SQL语法有错误;

我也尝试了下面的查询,但仍然得到相同的错误。

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

请帮忙。

mysql
2个回答
3
投票

这些是属于查询的from部分的表。

做这个:

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

2
投票

您在第二个子查询中缺少from,因此您在任何表中都没有执行select语句。

在你提到的第二个查询中,只需将* from作为

select * from (select 1 as place, 'Free' as name union select 2 as place,'Booked' as name ) as d 
© www.soinside.com 2019 - 2024. All rights reserved.