我想结合以下SQL查询。 现在我打电话给他们两次,但我想我可以用它来处理它。 我试过但无法找到解决方案。任何人都可以为我提供组合SQL。我知道我使用的是MSQL而不是MISQLI或PDO。
$lsel_first = mysql_query("select * from table_test WHERE owner = '$id' AND ownersecond = '0' AND catogory = '1' AND type = '$car[id]' AND caseB = '0' AND (timeback < TIMESTAMP(NOW()) OR timeback = '0000-00-00 00:00:00') ");
$first = mysql_num_rows($lsel_first);
$lsel_second = mysql_query("select * from table_test WHERE ownersecond = '$id' AND catogory = '1' AND type = '$car[id]' AND caseB = '0' AND (timeback < TIMESTAMP(NOW()) OR timeback = '0000-00-00 00:00:00') ");
$second = mysql_num_rows($lsel_second);
答案 0 :(得分:0)
下面:
mysql_query("select * from table_test
WHERE ((owner = '$id' AND ownersecond = '0') OR ownersecond = '$id')
AND catogory = '1' AND type = '$car[id]' AND caseB = '0'
AND (timeback < TIMESTAMP(NOW()) OR timeback = '0000-00-00 00:00:00') ");
答案 1 :(得分:0)
使用union
select * from table_test WHERE ownersecond = '$id' AND catogory = '1'
AND type = '$car[id]' AND caseB = '0' AND (timeback < TIMESTAMP(NOW())
OR timeback = '0000-00-00 00:00:00') union select * from table_test
WHERE ownersecond = '$id' AND catogory = '1' AND type = '$car[id]'
AND caseB = '0' AND (timeback < TIMESTAMP(NOW())
OR timeback = '0000-00-00 00:00:00')