我的代码只有在NOT IN中删除一个(SELECT)时才能正常,如果我在NOT IN中添加两个(SELECT),它就是echo array();首先,我想获得val =那些值和mark ='major'的果实。然后我想要删除任何标记='age'或mark ='ripe'的水果,所以我使用OR fruit NOT IN。我已经检查了NOT IN中的SELECT,当它们独自时它是可以的。
<?php
$dia = $wpdb->get_results( $wpdb->prepare("
SELECT fruit FROM table WHERE val IN (%s,%s,%s) AND mark = 'major' OR fruit NOT IN (
(SELECT fruit FROM table WHERE cat='uncommon' AND val = %s AND mark='age'),
(SELECT fruit FROM table WHERE cat='uncommon' AND val = %s AND mark='ripe')) GROUP BY fruit
",$sym1,$sym2,$sym3,$age,$ripe));
?>
答案 0 :(得分:1)
你不需要两个查询,你只需要改变你的条件。变化:
(SELECT fruit FROM table WHERE cat='uncommon' AND val = %s AND mark='age')
要:
(SELECT fruit FROM table WHERE cat='uncommon' AND (val = %s AND mark='age') OR (val = %s AND mark='ripe'))
否则您需要汇总查询。