mysql PHP SQL语句不是内部连接

kpbwa7wx  于 2023-11-16  发布在  Mysql
关注(0)|答案(1)|浏览(87)

我的SQL语句有问题。我有这些表和列:
第一个月
locations: id, location
styles: id,name
当我尝试运行sql来内部连接这些表在一起时,它不正确地工作,酒店信息被获取,但没有添加位置或样式:这是函数:

$stmt = $this->Connect()->prepare('SELECT
                 hotels.id,
                 hotels.name AS hotel_name,
                 hotels.stars,
                 hotels.check_in,
                 hotels.check_out,
                 hotels.location_id,
                 hotels.style_id
                 FROM hotels
                 INNER JOIN locations ON hotels.location_id = locations.id
                 INNER JOIN styles ON hotels.style_id = styles.id
                 ;');

字符串
我做错什么了吗?谢谢。

3hvapo4f

3hvapo4f1#

你没有从其他2个表中选择列,这就是为什么你没有得到信息。你应该这样做:

$stmt = $this->Connect()->prepare('SELECT
                 hotels.id,
                 hotels.name AS hotel_name,
                 hotels.stars,
                 hotels.check_in,
                 hotels.check_out,
                 hotels.location_id,
                 hotels.style_id,
                 locations.location,
                 styles.name as style_name
                 FROM hotels
                 INNER JOIN locations ON hotels.location_id = locations.id
                 INNER JOIN styles ON hotels.style_id = styles.id
                 ;');

字符串

相关问题