Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/78.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在mysql中搜索记录时如何处理这种情况?_Mysql_Sql_Database - Fatal编程技术网

在mysql中搜索记录时如何处理这种情况?

在mysql中搜索记录时如何处理这种情况?,mysql,sql,database,Mysql,Sql,Database,我正在开发一个PHP/MYSQL搜索模块,在这个模块中,我必须根据许多不同的条件搜索表,我有大约11个表,我使用了多个连接来创建一个MYSQL查询,并且基于where子句,我打算搜索特定的记录,下面是我正在使用的MYSQL查询 SELECT prop.id, prop.serial, prop.title, prop.rating, prop.addDate, prop.approve, prop.status, prop.user_id as userId, user_det.email as

我正在开发一个PHP/MYSQL搜索模块,在这个模块中,我必须根据许多不同的条件搜索表,我有大约11个表,我使用了多个连接来创建一个MYSQL查询,并且基于where子句,我打算搜索特定的记录,下面是我正在使用的MYSQL查询

SELECT
prop.id,
prop.serial,
prop.title,
prop.rating,
prop.addDate,
prop.approve,
prop.status,
prop.user_id as userId,
user_det.email as email,
user_det.name as name,
prop.area_id as areaId,
area.name as areaName,
area.zipCode as zipCode,
area.city_id as cityId,
city.name as cityName,
city.state_id as stateId,
state.name as stateName,
state.country_id as countryId,
country.name as countryName,
prop.subCategory_id as subCategoryId,
subCat.name as subCategoryName,
subCat.category_id as categoryId,
cat.name as categoryName,
prop.transaction_id as transactionId,
trans.name as transactionName,
price.area as landArea,
price.price as priceSqFt,
price.total_price as totalPrice,
features.bedroom,
features.bathroom,
features.balcony,
features.furnished,
features.floorNum,
features.totalFloor
FROM properties prop 
LEFT JOIN user_details user_det ON (prop.user_id = user_det.user_id) 
LEFT JOIN areas area ON (prop.area_id = area.id) 
LEFT JOIN cities city ON (area.city_id = city.id) 
LEFT JOIN states state ON (city.state_id = state.id) 
LEFT JOIN countries country ON (state.country_id = country.id) 
LEFT JOIN subCategories subCat ON (prop.subCategory_id = subCat.id) 
LEFT JOIN categories cat ON (subCat.category_id = cat.id) 
LEFT JOIN transactions trans ON (prop.transaction_id = trans.id) 
LEFT JOIN prop_prices price ON (price.property_id = prop.id) 
LEFT JOIN prop_features features ON (features.property_id = prop.id)
虽然在这里一切都很好,但我有一个叫做
prop\u的表,下面是这个表的内容

由于上面的表有多个
属性\u id
如果我使用联接查询它,那么根据我使用的
联接的类型,它将返回重复记录或单个记录,而忽略其他记录。所以我想用这种方式来处理

使用表prop_仅处理不返回结果的条件。 例如,我正在搜索一个设施id为1、5、9、17和24的酒店,那么它应该检查
prop_commercies
表中是否存在所有记录,即在本例中为1、5、9、17和24。并返回包含上述所有选定列的相应记录

我对使用MySQL处理这种情况一无所知。我该怎么做

谢谢。

您说过“检查
属性表中是否存在所有记录”,这是这里的关键词

SELECT ...
FROM properties AS prop
LEFT JOIN ...
WHERE EXISTS (SELECT 1 FROM prop_amenities AS pa WHERE pa.property_id = prop.property_id AND pa.amenity_id = 7);