Php SQL非重复子查询
可以将两个查询合并为一个查询吗 非常感谢Php SQL非重复子查询,php,mysql,sql,Php,Mysql,Sql,可以将两个查询合并为一个查询吗 非常感谢 $colname_Recordset_hot = "-1"; if (isset($_GET['Search'])) { $colname_Recordset_hot = $_GET['Search']; } $colnamef1_Recordset_hot = "%"; if (isset($_GET['f1'])) { $colnamef1_Recordset_hot = $_GET['f1']; } mysql_select_db($dat
$colname_Recordset_hot = "-1";
if (isset($_GET['Search'])) {
$colname_Recordset_hot = $_GET['Search'];
}
$colnamef1_Recordset_hot = "%";
if (isset($_GET['f1'])) {
$colnamef1_Recordset_hot = $_GET['f1'];
}
mysql_select_db($database_con_amazing, $con_amazing);
$query_Recordset_hot = sprintf("SELECT * FROM Hotel WHERE publish = 1 AND ad_country LIKE %s AND tag_1 LIKE %s OR ad_city LIKE %s OR category LIKE %s OR name LIKE %s OR tag_1 LIKE %s OR tag_2 LIKE %s OR tag_3 LIKE %s", GetSQLValueString("%" . $colname_Recordset_hot . "%", "text"),GetSQLValueString("%" . $colnamef1_Recordset_hot . "%", "text"),GetSQLValueString("%" . $colname_Recordset_hot . "%", "text"),GetSQLValueString("%" . $colname_Recordset_hot . "%", "text"),GetSQLValueString("%" . $colname_Recordset_hot . "%", "text"),GetSQLValueString("%" . $colname_Recordset_hot . "%", "text"),GetSQLValueString("%" . $colname_Recordset_hot . "%", "text"),GetSQLValueString("%" . $colname_Recordset_hot . "%", "text"));
$Recordset_hot = mysql_query($query_Recordset_hot, $con_amazing) or die(mysql_error());
$row_Recordset_hot = mysql_fetch_assoc($Recordset_hot);
$totalRows_Recordset_hot = mysql_num_rows($Recordset_hot);
mysql_select_db($database_con_amazing, $con_amazing);
我想在“选择不同的标记1”列上获得其他结果,但不想运行同一查询两次。您应该能够使用
联合所有
组合查询:
SELECT CustomerName
FROM Customers
WHERE name LIKE %s
UNION ALL
SELECT DISTINCT address
FROM Customers
WHERE name LIKE %s;
我不确定这有什么好处。编辑您的问题并显示您想要得到的结果。至少对我来说,这个问题还不清楚。您可以共享一些示例数据和您试图实现的结果吗?您可以创建一个存储过程,该过程将返回两个不同的记录集。问题用完整代码编辑