gpt4 book ai didi

php - 如何使用Join从另一个表中仅获取一条记录

转载 作者:行者123 更新时间:2023-11-29 14:04:51 24 4
gpt4 key购买 nike

我有一张酒店表格。我还有一张酒店图像表格。对于特定酒店,酒店图像表格中会有多个图像。

我只需要获取所有酒店的一张图像。使用左连接时,我获取特定酒店的所有图像。我只需要所有酒店的一张图像。

酒店餐 table

    CREATE TABLE IF NOT EXISTS `tbl_hotel` (
`int_hotel_id` int(11) NOT NULL auto_increment,
`str_country_id` varchar(5) NOT NULL,
`str_hotel_name` varchar(20) default NULL,
`int_property_type_id` int(11) default NULL,
`int_hotel_theme_id` int(11) default NULL,
`str_hotel_facility` varchar(50) default NULL,
`str_star_category` varchar(10) default NULL,
`str_web_url` varchar(30) default NULL,
`str_hotel_mail_id` varchar(25) default NULL,
`txt_hotel_description` text,
`str_hotel_city_name` varchar(50) default NULL,
`str_hotel_address` text NOT NULL,
`str_hotel_address2` text NOT NULL,
`int_hotel_zip_code` varchar(20) default NULL,
`str_hotel_phone` varchar(20) default NULL,
`str_hotel_fax_no` varchar(20) default NULL,
`bit_allow_booking` tinyint(4) default NULL,
`bit_active` tinyint(4) NOT NULL default '0',
`str_account_type` varchar(200) NOT NULL,
PRIMARY KEY (`int_hotel_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=95 ;

酒店图片

CREATE TABLE IF NOT EXISTS `tbl_hotel_image` (
`int_image_id` int(11) NOT NULL auto_increment,
`str_image_name` varchar(50) default NULL,
`txt_image_description` text,
`int_hotel_id` int(11) default NULL,
`bit_main_image` tinyint(4) default NULL,
`bit_active` tinyint(4) default NULL,
PRIMARY KEY (`int_image_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=119 ;

最佳答案

连接绑定(bind)了两个表,但 [GROUP BY] 的作用类似于记录压缩,获取具有相同值的记录,在本例中,它仅从 tbl_hotel_imgage.int_hotel_id here 获取一条记录和here你可以找到该语句的更多信息。

    Select * from 
tbl_hotel inner join tbl_hotel_image on
tbl_hotel_image.int_hotel_id=tbl_hotel.int_hotel_id
Group by
tbl_hotel_image.int_hotel_id;

关于php - 如何使用Join从另一个表中仅获取一条记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14544312/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com